@@ -18,6 +18,8 @@ import (
1818 "context"
1919 "fmt"
2020 "os"
21+ "slices"
22+ "strings"
2123 "testing"
2224 "time"
2325
@@ -42,23 +44,32 @@ func TestDebounceBatching(t *testing.T) {
4244 ctx , stop := context .WithCancel (context .Background ())
4345 t .Cleanup (stop )
4446
47+ trigger := types.Trigger {
48+ Path : "/" ,
49+ }
50+ matcher := watch.EmptyMatcher {}
4551 eventBatchCh := batchDebounceEvents (ctx , clock , quietPeriod , ch )
4652 for i := 0 ; i < 100 ; i ++ {
47- var action types. WatchAction = "a"
53+ var path = "/ a"
4854 if i % 2 == 0 {
49- action = "b"
55+ path = "/ b"
5056 }
51- ch <- fileEvent {Trigger : types.Trigger {Action : action }}
57+
58+ event := maybeFileEvent (trigger , path , matcher )
59+ require .NotNil (t , event )
60+ ch <- * event
5261 }
5362 // we sent 100 events + the debouncer
5463 clock .BlockUntil (101 )
5564 clock .Advance (quietPeriod )
5665 select {
5766 case batch := <- eventBatchCh :
58- require .ElementsMatch (t , batch , []fileEvent {
59- {Trigger : types.Trigger {Action : "a" }},
60- {Trigger : types.Trigger {Action : "b" }},
67+ slices .SortFunc (batch , func (a , b fileEvent ) int {
68+ return strings .Compare (a .HostPath , b .HostPath )
6169 })
70+ assert .Equal (t , len (batch ), 2 )
71+ assert .Equal (t , batch [0 ].HostPath , "/a" )
72+ assert .Equal (t , batch [1 ].HostPath , "/b" )
6273 case <- time .After (50 * time .Millisecond ):
6374 t .Fatal ("timed out waiting for events" )
6475 }
0 commit comments