forked from docker/go-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
46 lines (38 loc) · 858 Bytes
/
queue_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package events
import (
"fmt"
"sync"
"testing"
"time"
)
func TestQueue(t *testing.T) {
const nevents = 1000
ts := newTestSink(t, nevents)
eq := NewQueue(
// delayed sync simulates destination slower than channel comms
&delayedSink{
Sink: ts,
delay: time.Millisecond * 1,
})
time.Sleep(10 * time.Millisecond) // let's queue settle to wait conidition.
var wg sync.WaitGroup
for i := 1; i <= nevents; i++ {
wg.Add(1)
go func(event Event) {
if err := eq.Write(event); err != nil {
t.Fatalf("error writing event: %v", err)
}
wg.Done()
}("event-" + fmt.Sprint(i))
}
wg.Wait()
checkClose(t, eq)
ts.mu.Lock()
defer ts.mu.Unlock()
if len(ts.events) != nevents {
t.Fatalf("events did not make it to the sink: %d != %d", len(ts.events), 1000)
}
if !ts.closed {
t.Fatalf("sink should have been closed")
}
}