From 57faa3fe6aa5fe4ae684e7686fdd0a96aeac392c Mon Sep 17 00:00:00 2001 From: mwfj Date: Wed, 27 May 2026 19:56:59 +0800 Subject: [PATCH] Fix ci failure issue --- .../observability_connection_metrics_test.h | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/observability/observability_connection_metrics_test.h b/test/observability/observability_connection_metrics_test.h index 53c466f5..218cf70c 100644 --- a/test/observability/observability_connection_metrics_test.h +++ b/test/observability/observability_connection_metrics_test.h @@ -481,6 +481,16 @@ inline void TestNetAcceptedIsMonotonic() { "reactor.net.connections.accepted"); constexpr int N = 5; + // Send a real HTTP request and drain the response per connection. + // A bare connect+close races the accept dispatcher on slow CI + // runners — the RST can arrive before the accept callback fires, + // losing the +1 on `reactor.net.connections.accepted`. Driving a + // full request/response cycle forces the accept to complete + // before the close. + const std::string req = + "GET /h HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\r\n\r\n"; for (int i = 0; i < N; ++i) { int fd = ConnectTcp(port); if (fd < 0) { @@ -489,15 +499,21 @@ inline void TestNetAcceptedIsMonotonic() { TestFramework::TestCategory::OTHER); return; } - // Open + immediately close. The accept-time +1 fires - // regardless of any later HTTP traffic. + if (!SendAll(fd, req)) { + ::close(fd); + TestFramework::RecordTest(TAG, false, + "send failed at i=" + std::to_string(i), + TestFramework::TestCategory::OTHER); + return; + } + (void)DrainSocket(fd, 500); ::close(fd); - std::this_thread::sleep_for(std::chrono::milliseconds(20)); } - // Poll until the dispatcher drains the accept queue or 2 s elapse. - // A fixed 200 ms sleep is insufficient on slow CI runners. + // Poll for the counter to reach N — the accept-time bump runs on + // the dispatcher thread, so even after the response drains there + // is a small visibility gap before the Snapshot picks it up. { - auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(2); + auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5); while (std::chrono::steady_clock::now() < deadline) { auto snap_poll = fix.manager->meter_provider()->Snapshot(); double delta_poll = SumCounter(snap_poll,