Skip to content

Fix ci failure issue#46

Merged
mwfj merged 1 commit into
mainfrom
fix-flake-unit-test-issue
May 27, 2026
Merged

Fix ci failure issue#46
mwfj merged 1 commit into
mainfrom
fix-flake-unit-test-issue

Conversation

@mwfj

@mwfj mwfj commented May 27, 2026

Copy link
Copy Markdown
Owner

Fix flaky ObsConnMetrics: net.connections.accepted monotonic on slow CI runners

Closes #45.

Summary

TestNetAcceptedIsMonotonic in test/observability/observability_connection_metrics_test.h was failing intermittently on GitHub Actions shared runners with delta=4.000000 expected>=5. The test opened 5 TCP connections in a tight loop with immediate close() and a 20 ms inter-connection sleep, then polled the accepted counter for up to 2 s.

On slow / contended runners one of the connect+close cycles completed before the accept dispatcher processed the connection — the TCP RST arrived before (or nearly simultaneously with) the accept callback that increments reactor.net.connections.accepted. The counter only reached 4 and the test failed.

Fix

Replace the bare connect → close loop with connect → send GET /h → drain response → close (Option 2 from the issue). Driving a full HTTP request/response cycle per connection forces the accept callback to complete before the close, making the +1 deterministic instead of timing-dependent.

The post-loop snapshot poll deadline is also bumped from 2 s to 5 s as a backstop for the small dispatcher-thread visibility gap between the response draining on the client side and the Snapshot() picking up the counter bump.

The Connection: close request header keeps each connection short-lived so the test still exercises the accept-counter path under repeated open/close (which was the original intent), without changing the assertion shape (delta >= N).

Changes

  • test/observability/observability_connection_metrics_test.hTestNetAcceptedIsMonotonic now sends a minimal HTTP request and drains the response on each of the N connections; poll deadline raised from 2 s → 5 s; stale "accept-time +1 fires regardless of any later HTTP traffic" comment replaced with the actual race rationale.

No production code changed. Test-only fix, ~15-line diff in a single file.

Test plan

  • make -j4 test_runner — clean build.
  • ./test_runner obs_connection_metrics × 20 — all 20 runs pass ([PASS] ObsConnMetrics: net.connections.accepted monotonic over N opens).
  • Stress under heavy CPU contention (4 background busy-loop threads simulating loaded CI) × 10 — 10/10 passes.
  • CI matrix: gcc / clang / ASan+UBSan / TSan-rest (auto-picked up by obs_connection_metrics membership in the existing all-suites jobs).

Notes for reviewer

  • This is in the same class of CI timing sensitivity as Flaky test: ObsConnMetrics H1 protocol gauge read races AttachTransportObservability #43 (ObsConnMetrics protocol gauge race).
  • The DrainSocket(fd, 500) call is a 500 ms ceiling, not a fixed sleep — it returns as soon as the response bytes arrive, so the per-connection cost on a healthy runner is microseconds, not 500 ms.
  • The catch envelope already on TestFramework::RecordTest covers any exception escapes from SendAll / DrainSocket; the explicit send failed short-circuit just gives a more diagnostic failure message than a generic catch.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the TestNetAcceptedIsMonotonic test in observability_connection_metrics_test.h to prevent race conditions on slow CI runners. Instead of immediately closing the socket after connecting, the test now sends a full HTTP request and drains the response before closing the connection. Additionally, the polling deadline has been increased from 2 seconds to 5 seconds. I have no feedback to provide as there are no review comments.

@mwfj mwfj merged commit de56248 into main May 27, 2026
6 checks passed
@mwfj mwfj deleted the fix-flake-unit-test-issue branch May 27, 2026 12:20
@mwfj mwfj mentioned this pull request May 28, 2026
6 tasks
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.

Flaky CI: ObsConnMetrics net.connections.accepted monotonic test loses 1 of 5 connections on slow runners

1 participant