test: fix test_flushable_buckets_carry_all_batches assertion drift#46
Conversation
The test asserted one RecordBatch per insert, but inserts cross MAX_BATCH_COUNT_PER_BUCKET and trigger insert-time coalesce under the bucket lock — so 10 single-row inserts come back as 2 RecordBatches, not 10. The flush path actually only cares that every row makes it through; the batch-count breakdown is an implementation detail of the in-bucket coalesce gate. Rewrite the assertion to check rows (no loss) plus a bounded-batch-count sanity guard, and explain the coalesce trade-off in the test comment so the next reader doesn't bring the loose assertion back. Was failing on master before this PR (verified via git stash); this removes a CI gate that's been red on every PR.
Code ReviewOverviewThis PR fixes a broken test ( The change is well-reasoned and the PR description explains the root cause clearly. CorrectnessThe new assertions are logically sound:
The bound analysis in the comment is correct: coalesce fires when Suggestions1. let total_rows = MAX_BATCH_COUNT_PER_BUCKET + 2; // ensure coalesce fires at least onceCurrently 2. The bound assertion implicitly assumes The coalesce gate at line 1673: if g.len() > MAX_BATCH_COUNT_PER_BUCKET && bucket_bytes <= MAX_BATCH_BYTES_FOR_COALESCE {The batch-count bound only holds when the byte-size guard also passes. For tiny single-row inserts in a test this is fine, but the comment presents the bound as unconditional. A one-liner noting the dependency would prevent a future reader from assuming this bound applies under memory pressure: // Bound holds here because single-row test batches stay well under MAX_BATCH_BYTES_FOR_COALESCE.3. Minor: assertion message for The raw assert_eq!(flushable[0].row_count, total_rows);Consider adding one for consistency with the surrounding assertions: assert_eq!(flushable[0].row_count, total_rows, "cached row_count diverged from total inserts");Test CoverageThe existing SummaryClean, well-explained fix. The main actionable item is making Verdict: Approve with minor suggestions. The core logic is correct; the derived-constant suggestion is worth addressing before merge to avoid a future silent test regression. |
Summary
PR #45 was squash-merged but left CI red on master:
test_flushable_buckets_carry_all_batcheswas pre-existing failing on master before #45 and is still red now. This is the test fix that was on the original PR branch but dropped during squash.The test asserted one RecordBatch per insert, but inserts crossing
MAX_BATCH_COUNT_PER_BUCKETtrigger insert-time coalesce under the bucket lock — so 10 single-row inserts come back as 2 RecordBatches, not 10. The flush path actually only cares that every row makes it through; the batch-count breakdown is an implementation detail of the in-bucket coalesce gate.Rewrites the assertion to check rows (no loss) plus a bounded-batch-count sanity guard, and explains the coalesce trade-off in the test comment so the next reader doesn't bring the loose assertion back.
Test plan
cargo test --lib mem_buffer::tests::test_flushable_buckets_carry_all_batches— passes locally.