mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-26 18:16:47 -05:00
test(search): wait for the first debouncer run instead of sleeping
"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 <int>: 1 to equal <int>: 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 <jfd@butonic.de>
This commit is contained in:
1 parent
e864b06797
commit
a7b21848cf
1 file changed
+12
-4
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user