Skip to content

Commit 1646cd5

Browse files
authored
chore: fix racy test (#13196)
The application in test 1. imports profiler which would result in setting `bootstrap.profiler._scheduler._last_export` to a value > 0. 2. and sets the variable to a sentinel value from the module. This code is racy and could lead to unexpected failure, if 2. happens after 1. which was the case in [perf(profiling): code provenance outputs directories/.py files instead of all seen files](https://github.com/DataDog/dd-trace-py/pull/12616/files) https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-py/-/jobs/895566565 ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent f1afc48 commit 1646cd5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/contrib/gunicorn/wsgi_mw_app.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This app exists to replicate and report on failures and degraded behavior that can arise when using ddtrace with
33
gunicorn
44
"""
5+
56
import os
67

78

@@ -19,10 +20,6 @@
1920

2021
tracer.configure(trace_processors=[PingFilter()])
2122

22-
SCHEDULER_SENTINEL = -1
23-
assert bootstrap.profiler._scheduler._last_export not in (None, SCHEDULER_SENTINEL)
24-
bootstrap.profiler._scheduler._last_export = SCHEDULER_SENTINEL
25-
2623

2724
def aggressive_shutdown():
2825
tracer.shutdown(timeout=1)
@@ -37,7 +34,12 @@ def simple_app(environ, start_response):
3734
data = b"goodbye"
3835
else:
3936
payload = {
40-
"profiler": {"is_active": bootstrap.profiler._scheduler._last_export != SCHEDULER_SENTINEL},
37+
"profiler": {
38+
# Once the scheduler is initialized, the last_export is set to a
39+
# timestamp using time.time_ns()
40+
"is_active": bootstrap.profiler._scheduler._last_export
41+
> 0,
42+
},
4143
}
4244
data = json.dumps(payload).encode("utf-8")
4345

0 commit comments

Comments
 (0)