Skip to content

test(mux): read the gauge the three active_requests e2e tests are named after - #1541

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
test/mux-active-requests-gauge
Sep 26, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
test/mux-active-requests-gauge

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

e2e/src/tests/mux_tests.rs carried three tests named after http.active_requests — "H1 idle
timeout does not underflow", "H1 malformed request does not underflow", "H1 100 Continue does not
double-decrement" — under a file header advertising "P0: close() stream cleanup
(http.active_requests gauge leak)". None of the three read the gauge. The first opened five
connections, waited out their 408s, then asserted that a later request answered 200 — an assertion
that holds identically with or without an underflow.

Why they could not have been written in that shape

AggregatedMetric::update clamps a negative GaugeAdd to exactly 0 and logs an error!. The clamp
is deliberate and correct: a clear() under live traffic can legitimately drive a paired decrement
below a freshly reset baseline. Its consequence here is that "does not underflow" is not
observable from the gauge's value
when the gauge starts at zero.

correct            0 -> 1 -> 0
parasitic -1       0 -> 0        indistinguishable from the line above

The property the three tests were named for is one their shape could not express. They were written
for a change whose regression they therefore never witnessed.

The shape that makes it observable

http.active_requests is per worker process, not per connection. hold_one_request_in_flight puts
ONE legitimate request in flight on its own connection — held at the backend between
backend.receive and backend.send, an ordering guarantee rather than a sleep — and proves the
gauge reads exactly 1. The scenario under test then runs on other connections, and the assertion
is that the gauge still reads exactly 1. A parasitic decrement takes it to 0, which is
observable. Releasing the held request afterwards takes the gauge to 0 and pins the decrement a
charged stream does owe.

correct            1 -> 1 -> 0
parasitic -1       1 -> 0        (the unchanged-gauge assertion fails)

Built on #1537's tooling rather than beside it: query_proxy_gauge and await_active_requests_h1
are reused as they are, including the property that None is never folded into 0 — "the key does
not exist" and "the gauge reads zero" stay two observations, which is exactly what the three hollow
tests could never distinguish. Two helpers are added:

  • expect_active_requests_h1 takes a SINGLE sample, deliberately not a poll. A poll for a value the
    gauge already holds returns on its first iteration without ever observing the scenario — the
    vacuity this changeset is about.
  • raw_read_until_eof is the barrier that earns that single sample. A stream's access log, and with
    it the -1, is emitted before sozu shuts the frontend socket down, so a client that has read EOF
    has already been passed by every decrement that connection can emit. A deadline is reported as an
    error rather than folded into the bytes read.

setup_short_timeout_test now shortens request_timeout and nothing else. Which one is shortened is
load-bearing, not frugality: request_timeout is the timeout a frontend is armed with before its
first request links, so it alone decides how fast a silent connection collects its 408, while a
two-second front_timeout or back_timeout would answer the held request 504 and emit a
perfectly legitimate -1. The gauge would then read zero for a correct proxy, which is
indistinguishable from the underflow the test exists to catch.

The reds — there are two, not three

Each was obtained by removing one production guard on otherwise unmodified code. The production diff
of this branch is empty: git diff --name-only is CHANGELOG.md, doc/testing.md and
e2e/src/tests/mux_tests.rs.

Dropping the if self.request_counted condition in Stream::generate_access_log
(lib/src/protocol/mux/stream.rs), leaving events[0] = Some(MetricEvent::ActiveRequestFinished);
and self.request_counted = false; unconditional:

test tests::mux_tests::test_100_continue_no_double_decrement ... ok
test tests::mux_tests::test_malformed_request_no_underflow ... FAILED
test tests::mux_tests::test_idle_timeout_no_underflow ... FAILED
malformed: the 400s moved the gauge - wanted 1, sample Some(0)
idle-timeout: the 408s moved the gauge - wanted 1, sample Some(0)
test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 450 filtered out

The idle-timeout and malformed tests fall together, and that is the structure of the code rather
than a shortcut. Both scenarios reach the same access log on the same never-charged stream, and
there is no second guard between "no +1" and "no -1" to remove — two scenarios through one
guard, not two guards. No third distinct red was invented to disguise it.

Deleting the kawa::StatusLine::Response { code: 100, .. } arm in ConnectionH1::writable
(lib/src/protocol/mux/h1.rs), so a 100 falls through to the generic completion path:

test tests::mux_tests::test_malformed_request_no_underflow ... ok
test tests::mux_tests::test_idle_timeout_no_underflow ... ok
test tests::mux_tests::test_100_continue_no_double_decrement ... FAILED
100-continue: the interim response released the charge - wanted 2, sample Some(1)
test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 450 filtered out

That red is isolated, and it is observable only between the 100 and the 200: once the final
response has landed the gauge is back at the held baseline in the correct tree and in the mutated
one, because request_counted makes a second access log harmless. So the test samples while the
client holds its 100 and the backend still holds the 200.

A third candidate was measured and rejected. Removing the self.request_counted = false; clear
reddens nothing by the gauge: it trips its own debug_assert! at the same site first
(generate_access_log must leave request_counted false (gauge-underflow guard)), killing the worker
in all three tests. It could not have reddened them by the gauge anyway — no production path calls
generate_access_log twice on one stream, because the completion path clears metrics.start
through stream.metrics.reset() and Mux::close skips every stream whose metrics.start is
None. The 100-Continue test's doc comment records that, so its closing assertion is not read as
covering an idempotency guard no end-to-end test can reach.

After each red the mutated file was restored from git show HEAD:<path> and compared byte for byte
against a pre-mutation copy with cmp, and the three tests were re-run green.

Also

The file header no longer advertises a property it did not cover, and doc/testing.md's gauge
section gains the held-baseline technique together with its two rules — hold the baseline longer
than the scenario, and sample once after a barrier instead of polling.

Closes #1535

Signed-off-by: Florentin Dubois [email protected]

…ed after

`e2e/src/tests/mux_tests.rs` carried three tests named for `http.active_requests`
under a header advertising "P0: close() stream cleanup (http.active_requests gauge
leak)". None of the three read the gauge: the idle-timeout one opened five
connections, collected their 408s and asserted that a LATER request answered 200,
which holds identically with or without an underflow.

They could not have been written in that shape either. `AggregatedMetric::update`
clamps a negative `GaugeAdd` to exactly 0 — correctly, since a `clear()` under
live traffic can drive a paired decrement below a fresh baseline — so from a zero
baseline a parasitic `-1` reads 0 and so does a balanced request.

Move the baseline instead. `http.active_requests` is per worker process, so
`hold_one_request_in_flight` puts one legitimate request in flight on its own
connection, held at the backend between `receive` and `send`, and proves the gauge
reads 1. Each scenario then runs on other connections and must leave the gauge at
exactly 1; a parasitic decrement shows up as 0. Releasing the held request takes it
to 0 and pins the decrement a charged stream does owe.

`expect_active_requests_h1` takes a single sample rather than polling: a poll for a
value the gauge already holds returns on its first iteration without observing the
scenario at all. `raw_read_until_eof` earns that single sample — a stream's access
log, and with it the `-1`, is emitted before sozu shuts the frontend socket down —
and reports a deadline as an error instead of folding it into the bytes read.
`query_proxy_gauge` and `await_active_requests_h1` are reused unchanged, including
their refusal to fold `None` into `0`.

`setup_short_timeout_test` now shortens `request_timeout` and nothing else: it is
the timeout a frontend is armed with before its first request links, while a
two-second `front_timeout` or `back_timeout` would answer the held request 504 and
emit a perfectly legitimate `-1`, zeroing the gauge for a correct proxy.

Seen red on otherwise unmodified production code, and the reds are two, not three.
Dropping the `if self.request_counted` condition in `Stream::generate_access_log`
reddens the idle-timeout and malformed tests together (`wanted 1, sample Some(0)`,
1 passed / 2 failed): both reach the same access log on the same never-charged
stream, and there is no second guard between "no +1" and "no -1" to remove.
Deleting the `kawa::StatusLine::Response { code: 100, .. }` arm in
`ConnectionH1::writable` reddens the 100-Continue test alone (`wanted 2, sample
Some(1)`, 2 passed / 1 failed), observable only between the 100 and the 200.
Removing the `self.request_counted = false;` clear reddens nothing by the gauge —
it trips its own `debug_assert!` first — and no end-to-end test can reach that
guard, since no production path calls `generate_access_log` twice on one stream.

This changeset is test-only and no production file changed.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the test/mux-active-requests-gauge branch from eecf0b0 to 674c3b3 Compare September 25, 2026 23:39
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 7fb6500 into main Sep 26, 2026
28 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the test/mux-active-requests-gauge branch September 26, 2026 00:39
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.

e2e: three tests named after the http.active_requests gauge never read it, and their shape cannot see an unbalanced one

1 participant