Skip to content

test: time listen_only read separately to fix flake on slow runners - #2172

Merged
zariiii9003 merged 1 commit into
hardbyte:mainfrom
zariiii9003:fix-listen-only-timing-flake
Nov 30, 2026
Merged

zariiii9003 merged 1 commit into
hardbyte:mainfrom
zariiii9003:fix-listen-only-timing-flake

Conversation

@zariiii9003

Copy link
Copy Markdown
Collaborator

Summary of Changes

  • Fix a timing flake in TestThreadSafeBus::test_listen_only_while_recv_blocks (test/back2back_test.py). The 0.2 s bound on reading listen_only was measured from before the sleep(0.1), so any oversleep counted against the read; the PyPy/macOS CI job measured 0.234 s.
  • Time the read on its own and use the timings of the sibling test_state_while_recv_blocks:
-            pending = receiver.apply_async(self.bus2.recv, (0.3,))
+            pending = receiver.apply_async(self.bus2.recv, (1.0,))
             sleep(0.1)  # let the receiver take the receive lock

+            read_start = time()
             self.assertIs(self.bus2.listen_only, False)
-            self.assertLess(time() - start, 0.2)
+            self.assertLess(time() - read_start, 0.5)

             self.bus2.listen_only = True
             self.assertEqual(len(set_at), 1)
-            self.assertGreaterEqual(set_at[0] - start, 0.25)
+            self.assertGreaterEqual(set_at[0] - start, 0.9)
  • The docstring's Events and Evaluate sections are updated to match.

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe): test-only fix for a flaky test

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

No documentation or news fragment is needed: the change is test-only and not user-facing.

The test still catches the regressions it guards (CPython):

Code under test Result
unchanged passed
listen_only getter takes the receive lock failed: 0.900 not less than 0.5
listen_only setter without locks failed: 0.100 not greater than or equal to 0.9

Risk: easy to revert and touches one test only. The test now runs for about 1.0 s instead of 0.3 s.

@zariiii9003
zariiii9003 merged commit 9eb0179 into hardbyte:main Nov 30, 2026
25 of 26 checks passed
@zariiii9003
zariiii9003 deleted the fix-listen-only-timing-flake branch November 30, 2026 00:43
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.

1 participant