Repository navigation
Fix: Wait for the emitter's row count in a flaky Rust test - #1767
Conversation
…oken The emitter adds 1 to rows_emitted only after the write of a row returns (emitter.rs, after write_all). The mock server can get line "c" before that. The test read the count at once, so it could read 2 and fail with "left: 2, right: 3". This failed on main and on PRs. The test now polls the count until it is 3, with a 2 s limit. The assert stays, so a count that never gets to 3 still fails. To show the race, a 50 ms sleep before the bump makes the old test fail with "left: 2". The new test passes with the same sleep. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The diagnosis is correct. In Emitter::stream, bump(&self.rows_emitted, ...) runs only after the last wr.write_all(b"\r\n") returns. The mock server's read_stream can read the whole chunk (read_exact of n + 2 bytes) and send "c\n" on the channel before the emitter thread gets to the bump, so reading rows_emitted right after the third recv could see 2. Polling up to a 2 s deadline and keeping the final assert_eq! fixes the race without hiding a real regression: a count that never reaches 3 still fails, and the 2 s limit sits well under the 10 s recv timeout. Instant/Duration are already imported in the test module, and the Relaxed load is enough here because the test only needs the value to show up eventually.
I checked the other stats() asserts in this file and agree they don't have this race. captures_dropped_line_cap, captures_dropped_queue_bytes and rows_dropped (queue full) are all bumped synchronously in submit, and the queue tests use closed_addr() with no server.
Nit (advisory, not blocking): the commit subject is 74 characters, so GitHub cuts it off (...lines_arrive_in_order_with_t…). Something like fix: Wait for rows_emitted in the emitter order test would fit.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Rust (test only), security
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (Rust (praxis) green; a few unrelated Go jobs still pending)
What changed
record::emitter::tests::lines_arrive_in_order_with_token(praxis/filters/src/record/emitter.rs) fails sometimes withleft: 2, right: 3. It failed onmainand on #1765.rows_emittedonly after the write of a row returns. The mock server can get linecbefore that, and the test read the count at once.e.stats().rows_emitteduntil it is 3, with a 2 s limit. The assert stays, so a count that never gets to 3 still fails.The other
stats()asserts in this file do not have this race. Their counters change insubmit, before the line is sent, or the test has no server.How it was tested
rows_emittedbump makes the old test fail withleft: 2, as in CI. The new test passes with the same sleep. The sleep is not in this PR.praxis/, with the rustup toolchain:cargo fmt --check,cargo clippy --all-targets --locked -- -D warningsandcargo test --lockedpass.Assisted-By: Claude (Anthropic AI) noreply@anthropic.com