Fix flaky test caused by detector name collision in parallel CI jobs#417
Fix flaky test caused by detector name collision in parallel CI jobs#417timmarkhuff merged 11 commits intomainfrom
Conversation
test/unit/test_http_retries.py
Outdated
| return gl | ||
|
|
||
|
|
||
| @pytest.fixture(name="retry_detector_name") |
There was a problem hiding this comment.
I renamed this local fixture to avoid collision with the detector_name fixture I created in conftest.py.
…oundlight/python-sdk into tim/fix-flaky-detector-name-collision
| ) | ||
| assert completed_process.returncode == 0 | ||
| det_id_on_create = re.search("id='([^']+)'", completed_process.stdout).group(1) | ||
| match = re.search("id='([^']+)'", completed_process.stdout) |
There was a problem hiding this comment.
The Callable type annotation we added to this function promoted it from "untyped" to "typed" in mypy's eyes. Since check_untyped_defs is not enabled in our mypy config, mypy was previously skipping this function body entirely. The re.search().group() pattern was always unsafe, just invisible to the linter. Extracting the match and asserting it's not None satisfies mypy and also gives a clearer test failure message if the regex ever doesn't match.
| ) | ||
| assert completed_process.returncode == 0 | ||
| det_id_on_get = re.search("id='([^']+)'", completed_process.stdout).group(1) | ||
| match = re.search("id='([^']+)'", completed_process.stdout) |
There was a problem hiding this comment.
See comment above: https://github.com/groundlight/python-sdk/pull/417/changes#r2956546919
Problem
Test detector names were generated with
f"Test {datetime.utcnow()}", which has second-level precision and is evaluated at module import time. When parallel CI matrix jobs imported the same module within the same second, they produced identical detector names. This causedget_or_create_detectorcalls to fail with aunique_undeleted_name_per_setconstraint violation. Additionally, we have a lot of duplicated code for creating detector names, which could benefit from centralization.Fix
Added a
detector_namepytest fixture inconftest.pythat returns a callable which appends a random UUID suffix to the timestamp, guaranteeing uniqueness across parallel runs. Replaced all inline detector name formatting across the test suite with calls to this fixture.