Skip to content

test(python): wait for thread state in tcpip server interface tests - #3940

Merged
EmilyRagan merged 1 commit into
mainfrom
fix/flaky-tcpip-server-read-queue-timing
Sep 28, 2026
Merged

EmilyRagan merged 1 commit into
mainfrom
fix/flaky-tcpip-server-read-queue-timing

Conversation

@EmilyRagan

@EmilyRagan EmilyRagan commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Replaced the fixed time.sleep() calls that precede thread-dependent assertions in openc3/python/test/interfaces/test_tcpip_server_interface.py with the existing wait_for polling helper from test/test_helper.py.

Affected assertions:

  • test_server_read_only / test_read_and_write - read_queue_size() == 1
  • test_multiple_connections - num_clients() == 1 and == 0 after closing sockets
  • test_first_read_client_disconnect_cleans_up - num_clients() == 1 and len(read_interface_infos) == 0

Why it changed

test_server_read_only failed on Python 3.12 in https://github.com/OpenC3/cosmos/actions/runs/36072084541/attempts/1 (PR #3897, unrelated change):

test/interfaces/test_tcpip_server_interface.py:132: in test_server_read_only
    self.assertEqual(i.read_queue_size(), 1)
E   AssertionError: 0 != 1

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_for polls 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.py run 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 check and ruff format --check clean.

Review notes

Test-only change; no production code touched. Sleeps that only pace a blocking sock.recv() are left alone - recv blocks until data arrives, so they are not racing an assertion.

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

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.07%. Comparing base (ef52d2a) to head (8a5b1a7).

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     
Flag Coverage Δ
frontend 66.67% <ø> (+0.04%) ⬆️
python 80.11% <ø> (+<0.01%) ⬆️
ruby-api 82.61% <ø> (+0.06%) ⬆️
ruby-backend 85.65% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@EmilyRagan
EmilyRagan marked this pull request as ready for review September 25, 2026 16:20
@EmilyRagan EmilyRagan self-assigned this Sep 25, 2026
@EmilyRagan
EmilyRagan merged commit 104c84c into main Sep 28, 2026
42 checks passed
@EmilyRagan
EmilyRagan deleted the fix/flaky-tcpip-server-read-queue-timing branch September 28, 2026 15:27
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