Skip to content

test: Eliminate race conditions in event manager WebSocket tests#801

Merged
vdusek merged 1 commit intomasterfrom
fix/flaky-event-manager-ws-tests
Feb 18, 2026
Merged

test: Eliminate race conditions in event manager WebSocket tests#801
vdusek merged 1 commit intomasterfrom
fix/flaky-event-manager-ws-tests

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Feb 18, 2026

Summary

  • Fix flaky test_event_handling_on_platform test that failed intermittently on Windows CI
  • Root cause: dual-stack localhost binding created two sockets with different ports on Windows, and a race condition between server handler registration and message broadcasting
  • Extract shared _platform_ws_server helper binding to 127.0.0.1 with asyncio.Event synchronization — applied to all 6 WebSocket-based tests

Example failure: https://github.com/apify/apify-sdk-python/actions/runs/22132559177/job/63976018507?pr=782

Test plan

  • CI passes

🤖 Generated with Claude Code

The `test_event_handling_on_platform` test was flaky on Windows CI due to
two issues in the WebSocket test setup:

1. Dual-stack binding with different ports: `serve(host='localhost')` on
   Windows creates two sockets — IPv6 and IPv4 — with different random
   ports. The test read the port from `sockets[0]` (IPv6) but the client
   could resolve `localhost` to IPv4, hitting the wrong port.

2. Race condition: After `ApifyEventManager.__aenter__` returned, the
   test broadcast to `connected_ws_clients` without yielding to the event
   loop, so the server handler that populates the set may not have run yet.

Fix: Extract a shared `_platform_ws_server` helper that binds to
`127.0.0.1` (single socket) and uses `asyncio.Event` to synchronize
the server handler registration before any messages are sent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Feb 18, 2026
@vdusek vdusek self-assigned this Feb 18, 2026
@vdusek vdusek requested a review from Pijukatel February 18, 2026 09:07
@github-actions github-actions bot added this to the 134th sprint - Tooling team milestone Feb 18, 2026
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Feb 18, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.50%. Comparing base (c0a74b9) to head (0513a97).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #801   +/-   ##
=======================================
  Coverage   85.50%   85.50%           
=======================================
  Files          46       46           
  Lines        2691     2691           
=======================================
  Hits         2301     2301           
  Misses        390      390           
Flag Coverage Δ
e2e 35.48% <ø> (ø)
integration 57.59% <ø> (ø)
unit 72.46% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

@vdusek vdusek changed the title fix: Eliminate race conditions in event manager WebSocket tests test: Eliminate race conditions in event manager WebSocket tests Feb 18, 2026
@vdusek
Copy link
Copy Markdown
Contributor Author

vdusek commented Feb 18, 2026

or we can remove the test :)

Copy link
Copy Markdown
Contributor

@Pijukatel Pijukatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@vdusek vdusek merged commit c07461e into master Feb 18, 2026
58 of 59 checks passed
@vdusek vdusek deleted the fix/flaky-event-manager-ws-tests branch February 18, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. claude-code-assisted t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants