test: Advance an injected clock instead of sleeping past the TTL #16
No reviewers
Labels
No labels
blocked
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
s1d3sw1ped/scratchbox!16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ash/expiry-clock-9"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #9.
TestCreateReadThenExpireScratchcreated a scratch with a 120ms TTL and read it right away. A slow-racerunner could cross the TTL before the read and get 410 instead of 200 (run 2154).The server now checks expiry against an optional clock (
Server.now, nil meanstime.Now). The expiry tests use a one-hour TTL and push a test clock two hours forward instead of sleeping. The read half has hours of headroom, the expiry half is still asserted, and the sleeps are gone. The two sibling tests with the same short-TTL pattern (TestUploadedScratchViewAndRawBeforeAndAfterExpiry,TestParallelClientsExpiredScratchReadsReturnGone) get the same change.Proof on the jumpbox (go1.27.2):
go test -race -run 'TestCreateReadThenExpireScratch|TestUploadedScratchViewAndRawBeforeAndAfterExpiry|TestParallelClientsExpiredScratchReadsReturnGone' -count=50 ./internal/http/passes.go vet ./...andgofmt -lare clean.go test -race -count=3 ./...passes apart fromTestScratchPageServerMetaInjectionandTestFaviconServed, which need the built UI (no Node on the jumpbox, so I used a placeholderweb/static). They fail the same way on develop with that placeholder. CI builds the real UI.Revert is
git revert.GO on
5ffa72f.This fixes the flake the right way. Expiry now reads an injectable clock (nil falls back to time.Now, so production behavior is unchanged), and the three short-TTL tests use a one-hour TTL plus a pushed-forward test clock instead of sleeping. The read-before-expiry half gets hours of headroom and the expiry half is still asserted. The atomic offset keeps the parallel test race-safe. Build, gofmt and Go Tests are green on this head, and the head sits on the current develop tip.
No security surface here, so Linus can merge.