-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python_testing: generate controller's nodeid and shutdown subscription #34231
base: master
Are you sure you want to change the base?
python_testing: generate controller's nodeid and shutdown subscription #34231
Conversation
doublemis1
commented
Jul 8, 2024
•
edited
Loading
edited
- implementation of generate_random_node_id with exculdes values, the method add possibilty to run multiple test cases within one test session (the controllers' nodeid is the same for new controller in different test cases)
- ACE-1.2 script update: shutdown scubscriptions
PR #34231: Size comparison from 6e31453 to 9038d6d Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
# Usage of new implementation of ChipDeviceController cause the necessary to not use asyncio.run, | ||
# because the initialization of `asyncio.Lock` use the `asyncio.get_event_loop()` on init. | ||
# Usage of `asyncio.run()` and `asyncio.get_event_loop()` are exclusive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not 100% clear why this change is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of asyncio.run()
and asyncio.get_event_loop()
are mutually exclusive.
In python 3.9.18 creation of asyncio.Lock call asyncio.get_event_loop()
:
https://github.com/python/cpython/blob/3.9/Lib/asyncio/locks.py#L81
Example of reproduction:
import asyncio
async def hello():
print("hello")
lock_1 = asyncio.Lock()
asyncio.run(hello())
lock_2 = asyncio.Lock()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I will fix that issue on my side, while using the scripts.
Since it should be an issue in the Python 3.9 and older version.
def generate_random_nodeid(excluded_nodeid: typing.Optional[typing.List] = None) -> int: | ||
if excluded_nodeid: | ||
while True: | ||
node_id=random.randint(0, 2^64-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node ID 0 is not allowed (it means "unspecified").
There are some forbidden node IDs in the 0xFFFF_FFFx_xxxx_xxxx.
Also 2^64
is incorrect Python syntax and will lead to a very small number (66). Correct syntax is 2**64
.
node_id=random.randint(0, 2^64-1) | |
node_id=random.randint(1, 0xFFFF_FFEF_FFFF_FFFF) |
The above suggestion is spec compliant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for comment.
your suggestion has been applied
else: | ||
return random.randint(0, 2^64-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor loop not to need a repeated random.randint by just generating until "not invalid".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, used as recursive function
# Usage of new implementation of ChipDeviceController cause the necessary to not use asyncio.run, | ||
# because the initialization of `asyncio.Lock` use the `asyncio.get_event_loop()` on init. | ||
# Usage of `asyncio.run()` and `asyncio.get_event_loop()` are exclusive. | ||
loop = asyncio.get_event_loop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop says "deprecated since version 3.12" and documentation recommends to use alternatives.
I also am not very clear on what is going on based on the above comment and worry about the deprecation and warnings in the python documentation. Would it be correct to use get_running_loop for example?
Or is this code really needing to handle both coroutine vs non-coroutine use cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed change from the PR, the issue is visible on specific version of Python (Python 3.9.x and older), mentioned here #34231 (comment).
loop = asyncio.get_event_loop() | ||
return loop.run_until_complete(awaitable) | ||
|
||
def generate_random_nodeid(excluded_nodeid: typing.Optional[typing.List] = None) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List is not ideal, maybe Set would be better.
Why not set the default to an empty set, and then you do not need to handle None and everything can go through the same while True
branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function updated. As you suggested change the type of the excluded_nodeid, it suits better.
9038d6d
to
00f40c0
Compare
00f40c0
to
fa4d1cf
Compare
PR #34231: Size comparison from 90310f2 to fa4d1cf Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
* implementation of generate_random_node_id with exculdes values, the method add possibilty to run multiple test cases within one test session (the controllers' nodeid is the same for new controller in different test cases) * ACE-1.2 script update: shutdown scubscriptions Signed-off-by: Michał Szablowski <[email protected]>
fa4d1cf
to
26e8cfb
Compare
PR #34231: Size comparison from 9306418 to 26e8cfb Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|