Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions test/observability/observability_connection_metrics_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
Loading