-
Notifications
You must be signed in to change notification settings - Fork 6
Fix flaky test caused by detector name collision in parallel CI jobs #417
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2b09e79
fixing flaky test
timmarkhuff ee49af5
applying the fix in more places
timmarkhuff 4b1ac5f
trying a fixture-based approach
timmarkhuff a2cae39
Automatically reformatting code
9781a0a
renaming fixture
timmarkhuff 3b7d78d
Merge remote branch, resolve conflicts in favor of renamed fixture
timmarkhuff e60fad9
Automatically reformatting code
3c5b586
code cleanup
timmarkhuff d4d24b5
Merge branch 'tim/fix-flaky-detector-name-collision' of github.com:gr…
timmarkhuff bb836e7
adding type hint
timmarkhuff 8375191
fixing linter error
timmarkhuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import os | ||
| import re | ||
| import subprocess | ||
| from datetime import datetime | ||
| from typing import Callable | ||
| from unittest.mock import patch | ||
|
|
||
|
|
||
|
|
@@ -23,9 +23,9 @@ def test_list_detector(): | |
| assert completed_process.returncode == 0 | ||
|
|
||
|
|
||
| def test_detector_and_image_queries(): | ||
| def test_detector_and_image_queries(detector_name: Callable): | ||
| # test creating a detector | ||
| test_detector_name = f"testdetector {datetime.utcnow()}" | ||
| test_detector_name = detector_name("testdetector") | ||
| completed_process = subprocess.run( | ||
| [ | ||
| "groundlight", | ||
|
|
@@ -41,7 +41,9 @@ def test_detector_and_image_queries(): | |
| check=False, | ||
| ) | ||
| assert completed_process.returncode == 0 | ||
| det_id_on_create = re.search("id='([^']+)'", completed_process.stdout).group(1) | ||
| match = re.search("id='([^']+)'", completed_process.stdout) | ||
| assert match is not None | ||
| det_id_on_create = match.group(1) | ||
| # The output of the create-detector command looks something like: | ||
| # id='det_abc123' | ||
| # type=<DetectorTypeEnum.detector: 'detector'> | ||
|
|
@@ -59,7 +61,9 @@ def test_detector_and_image_queries(): | |
| check=False, | ||
| ) | ||
| assert completed_process.returncode == 0 | ||
| det_id_on_get = re.search("id='([^']+)'", completed_process.stdout).group(1) | ||
| match = re.search("id='([^']+)'", completed_process.stdout) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above: https://github.com/groundlight/python-sdk/pull/417/changes#r2956546919 |
||
| assert match is not None | ||
| det_id_on_get = match.group(1) | ||
| assert det_id_on_create == det_id_on_get | ||
| completed_process = subprocess.run( | ||
| ["groundlight", "get-detector", det_id_on_create], | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.