Skip to content

Fix flaky discovery test in discovery node#1345

Open
grafnu wants to merge 3 commits into
faucetsdn:masterfrom
grafnu:fix-flaky-discovery-test-12111036366940944222
Open

Fix flaky discovery test in discovery node#1345
grafnu wants to merge 3 commits into
faucetsdn:masterfrom
grafnu:fix-flaky-discovery-test-12111036366940944222

Conversation

@grafnu
Copy link
Copy Markdown
Collaborator

@grafnu grafnu commented May 30, 2026

No description provided.

google-labs-jules Bot and others added 3 commits May 29, 2026 21:26
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>
@grafnu grafnu requested a review from noursaidi May 30, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants