You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(asyncio): fix flaky test_asyncio test (#5498)
This change ensures that the MainThread Task with name 'None' is run
long enough to be targted by an event collector during this test.
Prior to this change the test
tests/profiling/collector/test_stack_asyncio.py::test_asyncio failed
occasionally due to a race condition between event collectors (which
scan threads) and collecting data about the MainThread with name=None.
If the collectors didn't run in time to catch the MainThread, no CPU
time would be recorded.
After this change, a sleep() statement guarantees the thread is running
long enough to be collected, and pointers have been added to enable
future changes in behavior.
Sample error:
```
assert wall_time_ns[t1_name] > 0
assert wall_time_ns[t2_name] > 0
if sys.platform != "win32":
# Windows seems to get 0 CPU for this
> assert cpu_time_found
E assert False
tests/profiling/collector/test_stack_asyncio.py:90: AssertionError
```
This change also modified a second test, which was failing due to referenced code lines. Prior
to this change, the test_asyncio test expected the profiler to identify exactly the first line of a method.
After this change, the tests ensures the profiler pointer is anywhere in the function.
Testing
This change was tested by increasing the collection interval
(StackSampleEvent interval) from (2 x sys.setswitchinterval) to (100 x
sys.setswitchinterval). These settings guaranteed 0% test success prior
to the fix and 100% test success after, over 50 runs.
Risks
None, this is an update to testing only.
## Checklist
- [x] Change(s) are motivated and described in the PR description.
- [x] Testing strategy is described if automated tests are not included
in the PR.
- [x] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines)
are followed.
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/)).
- [x] PR description includes explicit acknowledgement/acceptance of the
performance implications of this PR as reported in the benchmarks PR
comment.
## Reviewer Checklist
- [x] Title is accurate.
- [x] No unnecessary changes are introduced.
- [x] Description motivates each change.
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [x] Testing strategy adequately addresses listed risk(s).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] Release note makes sense to a user of the library.
- [x] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
0 commit comments