test: deterministic debounce test via synctest#745
Conversation
5ea2754 to
b916e5c
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes the flaky, wall-clock/network-driven debounce integration test (TestGenerateFromEvents) and replaces it with deterministic unit tests for newDebounceChannel using Go’s testing/synctest, addressing nondeterministic timing failures reported in #238.
Changes:
- Replaced
TestGenerateFromEvents(dockertest server + realtime.Sleep) withTestNewDebounceChannelbuilt ontesting/synctest. - Added deterministic subtests covering:
Min == 0passthrough,Minquiet-period coalescing, andMaxcap behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func TestNewDebounceChannel(t *testing.T) { | ||
| t.Run("passes events through when Min is zero", func(t *testing.T) { |
There was a problem hiding this comment.
Good catch — addressed in 9632402. TestNewDebounceChannel now redirects the standard logger to io.Discard for its duration and restores the previous writer via t.Cleanup, so the "Debounce … fired" lines no longer appear in test output.
9632402 to
6cbdd3a
Compare
|
@JamBalaya56562 same thing here, no issue or PR numbers in either PR titles or commit message. |
6cbdd3a to
6b64045
Compare
|
Done — dropped the issue number from the title and commit message, thanks! |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
6b64045 to
56ac89c
Compare
Summary
TestGenerateFromEventsdrives the debounce logic through a realdockertestHTTP server and wall-clocktime.Sleepcalls, so the timing of debounce firings races the OS scheduler / timer resolution and the test fails nondeterministically (off-by-one or worse). It reproduces onmainand is especially flaky on Windows. See #238.This PR replaces it with
TestNewDebounceChannel, which exercisesnewDebounceChanneldirectly inside atesting/synctestbubble. The fake clock makes theMinquiet-period coalescing and theMaxcap fire at exact, reproducible virtual times, removing the real network and wall-clock dependence entirely.Changes
internal/generator/generator_test.go: replaceTestGenerateFromEventswithTestNewDebounceChannel. Three deterministic subtests:Min == 0,Minquiet-period coalescing (a burst collapses to one event, firedMinafter the last event),Maxcap (output is forced out atMaxwhile events keep arriving).Notes
newDebounceChannelalready usestime.After, whichsynctestvirtualizes.testing/synctestis stable as of Go 1.25 (go.moddeclaresgo 1.25.5; the CI matrix tests Go 1.25 and 1.26). It is OS-independent, which removes the Windows timer-resolution flakiness at its root.go test -run TestNewDebounceChannel -count=200passes.Fixes #238