test: add unit test coverage for src/jobs/ - #831
Merged
Conversation
The src/jobs/ directory had zero test coverage despite running production-critical pruning, snapshot upload, and migration logic. Adds 13 inline #[cfg(test)] tests across all four modules: - block_pruning: job creation in both sync states + sync gate semantics - event_pruning: job creation + cutoff timestamp math - snapshot_upload: in-progress detection, empty shard filter, stale-backup cleanup (uses filetime to set old mtime), threshold constant - migrate_onchain_events: empty-store fast exit, mempool backpressure via wait_for_mempool_to_clear Adds filetime as a dev-dependency for the stale-backup test. Split out from #796 per review feedback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds unit tests to the production-critical src/jobs/ modules to increase coverage around pruning, snapshot upload behavior, and on-chain event migration/backpressure handling.
Changes:
- Added inline
#[cfg(test)]tests toblock_pruning,event_pruning,snapshot_upload, andmigrate_onchain_events. - Added
filetimeas a dev-dependency to support filesystem mtime manipulation in snapshot stale-backup tests. - Updated
Cargo.lockto reflect the new dev-dependency resolution.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/jobs/snapshot_upload.rs | Adds tests for in-progress detection, shard filtering, stale-backup cleanup, and the 12h threshold constant. |
| src/jobs/migrate_onchain_events.rs | Adds tests for empty-store fast-exit and mempool backpressure waiting behavior. |
| src/jobs/event_pruning.rs | Adds tests for job creation and retention/cutoff timestamp arithmetic. |
| src/jobs/block_pruning.rs | Adds tests for job creation under sync states and “sync gate” assertions. |
| Cargo.toml | Adds filetime = "0.2" under [dev-dependencies]. |
| Cargo.lock | Updates lockfile entries after adding filetime dev-dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
src/jobs/block_pruning.rssrc/jobs/event_pruning.rssrc/jobs/migrate_onchain_events.rs |
Per PR review (#831): the original cutoff/sync-gate tests just re-derived the arithmetic and watch::Receiver semantics, so they could pass even if the job's behavior changed. Extract the cutoff computation (and sync gate, for block_pruning) into pure helper functions used by both the job closures and the tests. - event_pruning::cutoff_timestamp(now, retention) -> u64 - block_pruning::pruning_cutoff(now, retention, sync_complete) -> Option<u64> (returns None when sync is incomplete, Some(cutoff) otherwise) Both helpers use saturating_sub so a misconfigured retention longer than the current farcaster time produces 0 instead of underflowing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Per PR review (#831): the test modules in snapshot_upload.rs and migrate_onchain_events.rs explicitly imported items (RocksDB, BlockStores, FarcasterNetwork, Arc, HashSet, mpsc, etc.) that are already in scope via `use super::*;` since the parent module imports them. Removed the duplicates; kept only items genuinely not in the parent (Config, MerkleTrie, TempDir, test_helper, StoreLimits). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
The
src/jobs/directory had zero test coverage despite running production-critical pruning, snapshot upload, and on-chain event migration logic. Adds 13 inline#[cfg(test)]tests across all four modules:block_pruning(4 tests) — job creation succeeds in both sync states; sync gate semantics (skips when not synced, runs when synced)event_pruning(3 tests) — job creation; cutoff timestamp =farcaster_time - retention.as_secs(); longer retention prunes further backsnapshot_upload(4 tests) —UploadAlreadyInProgressreturned when backup dir has recent contents; emptyonly_for_shard_idsfilter skips all backups; stale-backup contents cleaned up when mtime is older than 12h;STALE_BACKUP_THRESHOLDconstant is exactly 12 hoursmigrate_onchain_events(2 tests) — empty store completes migration immediately (fast exit beforewait_for_mempool_to_clear); mempool backpressure waits and recovers when size drops belowMAX_MEMPOOL_SIZEAdds
filetime = "0.2"as a[dev-dependencies]entry for the stale-backup test (used to set an old mtime on the temp directory).Split out from #796 per review feedback.
Test plan
cargo test jobspasses (13/13)🤖 Generated with Claude Code