chore(batch-imports): e2e test harness with misbehaving mock export APIs - #69815
Merged
Conversation
…arness A mock Mixpanel/Amplitude export server that can vary its response per download attempt (reordering, late data, rate limits, truncation), plus an in-process harness driving the real source, extractor, parser, and job fetch loop with restart simulation. select_and_fetch_next_chunk becomes pub so integration tests can drive it. Test plan in E2E_TEST_PLAN.md.
Happy paths, restart-mid-part resume, the reordered-export offset misalignment regression, rate limiting, empty days, and a chunk-size sweep - all asserting exactly-once output against generated ground truth.
2 tasks
nickbest-ph
marked this pull request as ready for review
July 10, 2026 00:02
Contributor
|
Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/mas..." | Re-trigger Greptile |
eli-r-ph
reviewed
Jul 10, 2026
| EmptyBody, | ||
| /// Valid gzip header, body cut mid-stream. | ||
| TruncatedGzip, | ||
| } |
eli-r-ph
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The batch import worker had no test coverage for how the Mixpanel/Amplitude export APIs actually behave across multiple downloads of the same date range. Their output is not byte-stable between calls (event ordering shifts, late data arrives), and our resume mechanism stores decompressed-byte offsets that are only meaningful against the exact byte stream they were committed against. When a pod replacement mid-part forces a re-download, the saved offset can land mid-line in the new stream and the job pauses with a confusing JSON parse error at byte 0 of the chunk. We hit exactly this in production.
All existing tests mock exports as byte-stable, so this entire failure class was invisible to CI.
Changes
tests/common/mock_export.rs: a stateful axum mock of the Mixpanel (gzip JSONL) and Amplitude (zip of.json.gzmembers) export APIs. Unlike httpmock it can vary its response per download attempt of the same day:Reorder(the incident behavior),LateData,RateLimit,NotFound,EmptyBody,TruncatedGzip. Bodies are derived deterministically from(seed, day, attempt)so tests compute exact ground truth, and generated lines have variable lengths so a reordered stream always misaligns byte offsets.tests/common/harness.rs: drives the real pipeline in-process. RealDateRangeExportSourcewith the production gzip/zip extractors, the production JSONL parser and per-provider transforms (hand-builtTransformContextwith the existing mock caches), through the DB-freeselect_and_fetch_next_chunkloop. Arestart()helper drops and rebuilds the source while keeping the committedJobState, which is exactly the shape of a deploy landing mid-part.tests/mixpanel_amplitude_e2e_test.rs: seven scenarios, all asserting exactly-once output against generated ground truth. No external services, ~2s total.src/job/mod.rs:select_and_fetch_next_chunkgoespub(crate)->pub. Its doc comment already describes it as the DB-free testable core; integration tests compile as external crates so they need the export.How did you test this code?
Automated only, no manual testing:
cargo test -p batch-import-worker --test mixpanel_amplitude_e2e_test).cargo fmtandcargo clippy --testsclean.ReordertoStablemakes the test fail, proving it detects the reorder misalignment specifically and not something incidental.Regressions each test group catches that nothing caught before:
date_range_export_streaming_test.rs) but not through the job loop with exactly-once output assertions.newline_delim's consumed-offset arithmetic end to end across chunk boundary shapes; unit tests cover single buffers only.Automatic notifications
Docs update
Not needed, test-only change plus one visibility widening.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Emitter, since the emit path is unit-covered and adds no discriminating power here.