Fix flaky discovery test in discovery node#1345
Open
grafnu wants to merge 3 commits into
Open
Conversation
The test `test_number_discovery_start_and_stop` hardcoded the exact number of events it expected within a 5-second sleep window. In slower CI environments or local testing, OS thread scheduling differences could cause an additional item to be published (e.g. 6 items instead of 5), causing the test to fail. This commit updates the assertion logic to verify structural invariants instead: it checks that the event sequence begins and ends with `None` (start and stop markers), and that the elements published in between are sequential string integers starting from `'1'`. Co-authored-by: grafnu <1066895+grafnu@users.noreply.github.com>
Replaced hardcoded `time.sleep(5)` with a deterministic polling loop that waits for the exact expected number of published events (start marker + 5 numbers = 6 total events) before signaling the system to stop. This resolves the issue where a variable number of events were published depending on machine thread scheduling, ensuring that tests fail based on incorrect behavior rather than execution speed. Co-authored-by: grafnu <1066895+grafnu@users.noreply.github.com>
Pass an explicit `range` argument to `NumberDiscovery` in tests instead of relying on the infinite generator. This allows us to use `task_thread.join()` to wait for exactly the defined number of events to be published, eliminating flaky behavior caused by variable execution speeds during fixed `time.sleep` intervals. Co-authored-by: grafnu <1066895+grafnu@users.noreply.github.com>
noursaidi
approved these changes
May 31, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.