test(python): wait for thread state in tcpip server interface tests - #3940
Merged
Merged
Conversation
test_server_read_only asserted read_queue_size() == 1 after a fixed 0.1s sleep, which is not long enough on a loaded CI runner and failed with "AssertionError: 0 != 1". Replace the fixed sleeps ahead of thread-dependent assertions with the existing wait_for polling helper so the tests wait on the condition instead of the clock. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3940 +/- ##
==========================================
+ Coverage 80.05% 80.07% +0.01%
==========================================
Files 901 901
Lines 68355 68355
Branches 2645 2698 +53
==========================================
+ Hits 54722 54732 +10
+ Misses 12961 12950 -11
- Partials 672 673 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
jmthomas
approved these changes
Sep 25, 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.



What changed
Replaced the fixed
time.sleep()calls that precede thread-dependent assertions inopenc3/python/test/interfaces/test_tcpip_server_interface.pywith the existingwait_forpolling helper fromtest/test_helper.py.Affected assertions:
test_server_read_only/test_read_and_write-read_queue_size() == 1test_multiple_connections-num_clients() == 1and== 0after closing socketstest_first_read_client_disconnect_cleans_up-num_clients() == 1andlen(read_interface_infos) == 0Why it changed
test_server_read_onlyfailed on Python 3.12 in https://github.com/OpenC3/cosmos/actions/runs/36072084541/attempts/1 (PR #3897, unrelated change):The test sends bytes to the server socket and then sleeps 0.1s before asserting that the read thread has queued a packet. 0.1s is comfortable on a developer machine but not guaranteed on a loaded CI runner, so the assertion races the thread. The other sleeps in this file sit in front of the same kind of assertion, so they are fixed together rather than waiting for each to fail on its own.
wait_forpolls at 5ms up to a 5s timeout and does not assert on timeout, so the caller's original assertion still produces the failure message.Testing strategy
uv run pytest test/interfaces/test_tcpip_server_interface.pyrun 5 times locally, 19 passed each time. Runtime dropped from ~3.2s to ~0.9s since polling returns as soon as the condition holds instead of always sleeping the full interval.ruff checkandruff format --checkclean.Review notes
Test-only change; no production code touched. Sleeps that only pace a blocking
sock.recv()are left alone -recvblocks until data arrives, so they are not racing an assertion.