Repository navigation
Make the job sweep test time-independent and fix timestamp ordering - #33
Merged
Merged
Conversation
TestSweepExpiredJobsDeletesOldWorkspaceOnly shrank the retention period to 100ms and needed the fresh job's completion and the sweep to finish inside it. A slow CI runner took longer, the fresh job counted as expired, and the test failed. App now has a clock tests can set (the same pattern as mailgun.Service), and the test puts the cutoff exactly on a boundary taken between the two completions, so a slow machine only widens the margins. jobRetentionPeriod becomes a constant again. Underneath was a real ordering bug. The store wrote timestamps with RFC3339Nano, which trims trailing zeros, and compares them as text in SQL, so "10:00:00.5Z" sorted before "10:00:00Z": a job completed half a second after a cutoff counted as expired. The alert tables already used a fixed-width format for exactly this reason; it is now the store-wide timeFormat and every timestamp write uses it. Reads still parse with RFC3339Nano, which accepts both, so existing rows need no migration and can misorder against new ones only within the same second. Co-Authored-By: Claude Opus 5.5 <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.
Why
TestSweepExpiredJobsDeletesOldWorkspaceOnlyfailed on CI during #32. It shrank job retention to 100 ms and needed "complete the fresh job, then sweep" to finish within that time. On a slow Windows runner it didn't, so the fresh job's workspace was swept.Underneath was a real bug. The store writes timestamps with
RFC3339Nano, which trims trailing zeros, and the expiry queries compare them as text (completed_at < ?). So10:00:00.5Zsorts before10:00:00Z, and a job completed half a second after a cutoff counted as expired. In production, with 30-day retention, that's harmless. In millisecond-scale tests it's a second source of random failures. The alert tables already avoid this with a fixed-width format.Changes
alertTimeFormatbecomes the store-widetimeFormat(nine fixed fraction digits). Every timestamp write uses it, covering jobs, submissions, deliveries and cutoffs. Reads still parse withRFC3339Nano, which accepts both formats, so there's no migration. Old and new rows can misorder only within the same second.nowclock field with aclock()method, the same pattern asmailgun.Service. The sweep measures retention against it, andjobRetentionPeriodis a constant again.expireEverythingmoves the clock forward instead of changing the shared retention period.Testing
go vet ./...andgo test ./...pass.Production behavior is unchanged apart from the sub-second ordering fix, so deploying this can wait for the next scheduled deploy.
🤖 Generated with Claude Code