Skip to content

Use testing/synctest in dedup queue tests#357

Merged
folbricht merged 1 commit into
masterfrom
synctest-dedupqueue
Jun 11, 2026
Merged

Use testing/synctest in dedup queue tests#357
folbricht merged 1 commit into
masterfrom
synctest-dedupqueue

Conversation

@folbricht

Copy link
Copy Markdown
Owner

Runs TestDedupQueueParallel and TestWriteDedupQueueParallelReadWrite inside testing/synctest bubbles (stable since Go 1.25, which this module already requires). Under the bubble's fake clock, time.Sleep only returns once every other goroutine in the bubble is durably blocked, which turns both tests' timing heuristics into guarantees.

TestDedupQueueParallel: The 1ms sleep in GetChunkFunc previously just made the store "artificially slow" and hoped all 10 goroutines piled up as waiters in time — a goroutine scheduled late would make a second store request, which is why the assertion hedged with requests <= 1 ("ideally just one"). The sleep now provably cannot complete until all other goroutines are blocked waiting on the in-flight request, so the assertion becomes a deterministic requests == 1. Also modernizes the counter to atomic.Int64 and the loop to wg.Go().

TestWriteDedupQueueParallelReadWrite: Previously, if reads and writes wrongly shared a queue, StoreChunk() would have just taken a second longer and still passed — the test couldn't actually detect the regression it was written for. It now asserts that zero fake time elapses across StoreChunk(), which fails if the write waits on the in-flight slow read. The 1s sleep no longer costs wall time, and the background read goroutine no longer leaks past the end of the test.

Both tests pass with -race -count=5.

Run TestDedupQueueParallel and TestWriteDedupQueueParallelReadWrite
inside synctest bubbles. The fake clock makes the previously
timing-dependent behavior deterministic:

- TestDedupQueueParallel: the sleep in GetChunkFunc now guarantees all
  goroutines have registered as waiters before the first request
  completes, so the assertion can require exactly one upstream request
  instead of "ideally just one".

- TestWriteDedupQueueParallelReadWrite: the test now asserts that no
  fake time elapses across StoreChunk(), proving the write does not
  queue behind the in-flight slow read. The 1s sleep no longer costs
  wall time and the background read goroutine no longer leaks past the
  test.
@folbricht folbricht merged commit 86eb6d0 into master Jun 11, 2026
3 checks passed
@folbricht folbricht deleted the synctest-dedupqueue branch June 11, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant