Use read_exact in test_connect_uds - #968
Conversation
AsyncReadExt::read succeeds on a short read and its return value was discarded, so a segmented delivery of the mock server's 9-byte response left buf holding a partial message padded with zeros, and the assertion compared that against b"it works!". Stream sockets are free to split a write_all across multiple reads, so this is a latent flake rather than a guaranteed failure. Made deterministic by splitting the mock server's write_all into 1 byte + 20ms + 8 bytes, which is legal stream behaviour: the test then fails every time before this change (left: [105, 0, 0, 0, 0, 0, 0, 0, 0], only the leading 'i' arrived) and passes after it. That perturbation is only a reproduction aid and is not part of this commit. Signed-off-by: Shanire <shanire86@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a latent test flake in connectors::tests::test_connect_uds by ensuring the test reads the full 9-byte mock-server response before asserting, which matches the semantics of stream sockets (where a single write_all may be split across multiple reads).
Changes:
- Replace
AsyncReadExt::read(with ignored returned length) withAsyncReadExt::read_exactintest_connect_udsto avoid short-read partial-buffer assertions.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Heads-up on the red check, so it doesn't cost a reviewer any time: the It trips on RUSTSEC-2026-0258 ( Two things that show it is pre-existing rather than caused by this PR:
This PR changes one line inside a Fixing it means moving off |
Fixes #967.
connectors::tests::test_connect_udsread the mock server's 9-byte response withAsyncReadExt::readand discarded the returned length, so a segmented delivery leftbufholding a partial message padded with zeros and the assertion failed. Streamsockets are free to split a
write_allacross reads, so this was a latent flake.The fix is one line:
read_exactinstead ofread.How it was verified
The flake was made deterministic rather than chased with repeated runs. Having the mock
server split its write into
1 byte + 20ms + 8 bytes— legal stream behaviour, notsabotage — makes the test fail every time before the change and pass after it. That
perturbation is a reproduction aid only and is not part of this commit.
main@0046038left: [105, 0, 0, 0, 0, 0, 0, 0, 0]105isi— only the first byte had arrived.Gates
Run on
main@0046038, in a Debian 13 container with rustc 1.97.1, before and afterthe patch:
cargo fmt --all -- --checkcargo check --workspacecargo clippy --all-targets --all -- --allow=unknown-lints --deny=warningscargo test -p pingora-core --lib --features rustls --no-fail-fastThe one failure (
connectors::l4::tests::test_bind_to_port_range_on_connect) is presenton unmodified
maintoo.One note on that measurement, since it initially looked worse than it was: my first run
showed 7 failures on the baseline and 6 with the patch. That difference was entirely my
environment — Docker's default network answers for
192.0.2.1(RFC 5737), so theconnect-timeout tests that use it as a black hole never time out and fail
non-deterministically. After adding
iptables -A OUTPUT -d 192.0.2.0/24 -j DROPbothsides settle at 572/1/2 with an empty symmetric difference.
I did not run the MSRV job locally (only 1.97.1 in the container), but that job runs
cargo check, which does not compile test code, and this change is test-only.cargo auditandcargo macheteare likewise left to CI; this change touches nomanifest.
Scope
pingora-core/src/listeners/mod.rshas the samelet _ = stream.read(&mut buf)shape intest_listen_tls, but that one only drains the request and never asserts on thecontents, so I left it alone.