From a7b21848cf0165c25bfaf64bdbc6d08dd50c92a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 13 Nov 2026 17:41:56 +0100 Subject: [PATCH] test(search): wait for the first debouncer run instead of sleeping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "doesn't trigger twice simultaneously" slept 100ms and assumed the first run had started by then. On a busy CI runner the 50ms debounce timer can fire later. The second Debounce then only resets the pending timer, both calls collapse into one run and the count never reaches 2: [FAILED] Timed out after 2.001s. Expected : 1 to equal : 2 The run now blocks on a channel until the test releases it. We wait for the first run to start, check that the second debounce does not start another run while it is in progress, then release it and expect the second run. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer --- .../search/pkg/service/event/debouncer_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/search/pkg/service/event/debouncer_test.go b/services/search/pkg/service/event/debouncer_test.go index 8169b36625..1f3d0a19db 100644 --- a/services/search/pkg/service/event/debouncer_test.go +++ b/services/search/pkg/service/event/debouncer_test.go @@ -56,19 +56,27 @@ var _ = Describe("SpaceDebouncer", func() { }) It("doesn't trigger twice simultaneously", func() { + // runs block until released, so the first one is still in progress for + // as long as the test needs it, however slow the machine is + release := make(chan struct{}) debouncer = event.NewSpaceDebouncer(50*time.Millisecond, 5*time.Second, func(id *sprovider.StorageSpaceId, _ bool) { if id.OpaqueId == "spaceid" { callCount.Add(1) } - time.Sleep(300 * time.Millisecond) + <-release }, log.NewLogger()) debouncer.Debounce(spaceid, nil, false) - time.Sleep(100 * time.Millisecond) // Let it trigger once + Eventually(func() int { + return int(callCount.Load()) + }, "2000ms").Should(Equal(1)) debouncer.Debounce(spaceid, nil, false) - time.Sleep(100 * time.Millisecond) // shouldn't trigger as the other run is still in progress - Expect(int(callCount.Load())).To(Equal(1)) + // shouldn't trigger as the other run is still in progress + Consistently(func() int { + return int(callCount.Load()) + }, "200ms").Should(Equal(1)) + close(release) Eventually(func() int { return int(callCount.Load()) }, "2000ms").Should(Equal(2))