Skip to content

test(e2e): give try_msg_close a failure path, and stop running 100 iterations that cannot fail - #1433

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
test/e2e-msg-close
Sep 22, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
test/e2e-msg-close

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

try_msg_close had no State::Fail anywhere in its body: its only State::
expression was the State::Success it ended on, and the response it read was
handed to println! and discarded. It ran 100 consecutive iterations of a check
that could not go red, so its green was not evidence of the connection-close
behaviour its name claims, while occupying the slot a real test would take.

It now observes four things, each bounded by its own deadline and each returning
State::Fail: the keep-alive exchange completes, the frontend session is still
open and idle when SoftStop is sent, that SoftStop closes it with a bare
half-close and no extra byte on the wire, and the worker then terminates. The
production code so covered is Mux::shutting_down, reached through
HttpSession::shutting_down from Server::shut_down_sessions.

The liveness check is what makes the close assertion mean anything. A read that
ends at EOF cannot distinguish "SoftStop closed the idle session" from "there
was no idle session left to close", so a regression that dropped keep-alive and
closed every frontend after one response would pass without it. It peeks the
socket over a 300ms window, which makes the EOF that follows attributable to
SoftStop. Not proved caused by it: the window ends before soft_stop() is sent,
so a close inside that remaining gap would still read as a pass. Nothing else
is in flight there, and the test records the bound as a known limitation.

The worker-termination check is bounded too. Worker::wait_for_server_stop is
JoinHandle::join, which returns Err only on a panic, so a worker that merely
never terminates hung the process instead of failing the test; it is now reached
through a JoinHandle::is_finished poll under a deadline. Every failing path also
stops and joins its worker, because that join is the only site reclaiming the
two scm UnixStreams and Worker has no Drop.

The read loops of e2e/src/tests/tests.rs collapse from four to one:
receive_with_deadline and assert_client_eof are now thin wrappers over a single
read_until, which reads the TcpStream directly because Client::receive reports a
half-close and an expired read timeout as the same None. A timed-out partial
read is reported as an incomplete response instead of borrowing the wording of
the protocol assertion, and the response budget rises from 500ms to the 1s its
siblings in this file already use.

n drops from 100 to 3. Every step blocks on its own deadline instead of on a
thread::sleep(100ms) landing on the right side of a race, so one iteration
already proves the property; nothing asserted here is statistical. Three
back-to-back iterations in one process are not three independent draws of the
SoftStop-versus-event-loop ordering either, since the response has just been
written and the loop is parked in epoll every time. What the repetition buys is
a cheap re-exercise of worker spawn, port allocation and teardown. Nothing
distinguishes 3 from 2; what is being removed is 100. The choice does not rest
on popularity: over the 402 real repeat_until_error_or source call sites on
main, n=5 is the modal value, not n=3.

Seen red three times before green, against production code that was then
restored: the keep_alive_frontend arm of ConnectionH1::writable inverted
(lib/src/protocol/mux/h1.rs), Mux::shutting_down_inner returning false from its
final can_stop arm, and an inverted Method::Head test in
HttpContext::on_response_headers. All three recipes are recorded in the test's
doc comment.

The seven TLS handshake tests that also run at n=100 all delegate to
try_tls_with_cert, which fails on an unresolved response and on a backend that
saw no request; they do not share this defect. They do share the unbounded join,
which this changeset does not fix.

Closes #1426

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

try_msg_close had no State::Fail anywhere in its body: its only State::
expression was the State::Success it ended on, and the response it read was
handed to println! and discarded. It ran 100 consecutive iterations of a check
that could not go red, so its green was not evidence of the connection-close
behaviour its name claims, while occupying the slot a real test would take.

It now observes four things, each bounded by its own deadline and each returning
State::Fail: the keep-alive exchange completes, the frontend session is still
open and idle when SoftStop is sent, that SoftStop closes it with a bare
half-close and no extra byte on the wire, and the worker then terminates. The
production code so covered is Mux::shutting_down, reached through
HttpSession::shutting_down from Server::shut_down_sessions.

The liveness check is what makes the close assertion mean anything. A read that
ends at EOF cannot distinguish "SoftStop closed the idle session" from "there
was no idle session left to close", so a regression that dropped keep-alive and
closed every frontend after one response would pass without it. It peeks the
socket over a 300ms window, which makes the EOF that follows attributable to
SoftStop. Not proved caused by it: the window ends before soft_stop() is sent,
so a close inside that remaining gap would still read as a pass. Nothing else
is in flight there, and the test records the bound as a known limitation.

The worker-termination check is bounded too. Worker::wait_for_server_stop is
JoinHandle::join, which returns Err only on a panic, so a worker that merely
never terminates hung the process instead of failing the test; it is now reached
through a JoinHandle::is_finished poll under a deadline. Every failing path also
stops and joins its worker, because that join is the only site reclaiming the
two scm UnixStreams and Worker has no Drop.

The read loops of e2e/src/tests/tests.rs collapse from four to one:
receive_with_deadline and assert_client_eof are now thin wrappers over a single
read_until, which reads the TcpStream directly because Client::receive reports a
half-close and an expired read timeout as the same None. A timed-out partial
read is reported as an incomplete response instead of borrowing the wording of
the protocol assertion, and the response budget rises from 500ms to the 1s its
siblings in this file already use.

n drops from 100 to 3. Every step blocks on its own deadline instead of on a
thread::sleep(100ms) landing on the right side of a race, so one iteration
already proves the property; nothing asserted here is statistical. Three
back-to-back iterations in one process are not three independent draws of the
SoftStop-versus-event-loop ordering either, since the response has just been
written and the loop is parked in epoll every time. What the repetition buys is
a cheap re-exercise of worker spawn, port allocation and teardown. Nothing
distinguishes 3 from 2; what is being removed is 100. The choice does not rest
on popularity: over the 402 real repeat_until_error_or source call sites on
main, n=5 is the modal value, not n=3.

Seen red three times before green, against production code that was then
restored: the keep_alive_frontend arm of ConnectionH1::writable inverted
(lib/src/protocol/mux/h1.rs), Mux::shutting_down_inner returning false from its
final can_stop arm, and an inverted Method::Head test in
HttpContext::on_response_headers. All three recipes are recorded in the test's
doc comment.

The seven TLS handshake tests that also run at n=100 all delegate to
try_tls_with_cert, which fails on an unresolved response and on a backend that
saw no request; they do not share this defect. They do share the unbounded join,
which this changeset does not fix.

Closes #1426

Signed-off-by: Florentin Dubois <[email protected]>
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: try_msg_close has no failure path, yet runs 100 consecutive iterations that cannot fail

1 participant