MCPcopy
hub / github.com/docker/compose / Test_BatchDebounceEvents

Function Test_BatchDebounceEvents

pkg/watch/debounce_test.go:27–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func Test_BatchDebounceEvents(t *testing.T) {
28 ch := make(chan FileEvent)
29 clock := clockwork.NewFakeClock()
30 ctx, stop := context.WithCancel(t.Context())
31 t.Cleanup(stop)
32
33 eventBatchCh := BatchDebounceEvents(ctx, clock, ch)
34 for i := range 100 {
35 path := "/a"
36 if i%2 == 0 {
37 path = "/b"
38 }
39
40 ch <- FileEvent(path)
41 }
42 // we sent 100 events + the debouncer
43 err := clock.BlockUntilContext(ctx, 101)
44 assert.NilError(t, err)
45 clock.Advance(QuietPeriod)
46 select {
47 case batch := <-eventBatchCh:
48 slices.Sort(batch)
49 assert.Equal(t, len(batch), 2)
50 assert.Equal(t, batch[0], FileEvent("/a"))
51 assert.Equal(t, batch[1], FileEvent("/b"))
52 case <-time.After(50 * time.Millisecond):
53 t.Fatal("timed out waiting for events")
54 }
55 err = clock.BlockUntilContext(ctx, 1)
56 assert.NilError(t, err)
57 clock.Advance(QuietPeriod)
58
59 // there should only be a single batch
60 select {
61 case batch := <-eventBatchCh:
62 t.Fatalf("unexpected events: %v", batch)
63 case <-time.After(50 * time.Millisecond):
64 // channel is empty
65 }
66}

Callers

nothing calls this directly

Calls 2

BatchDebounceEventsFunction · 0.85
FileEventTypeAlias · 0.85

Tested by

no test coverage detected