-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueue_test.go
More file actions
51 lines (42 loc) · 834 Bytes
/
queue_test.go
File metadata and controls
51 lines (42 loc) · 834 Bytes
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
47
48
49
50
51
package subee
import (
"context"
"testing"
"time"
)
type fakeMessage struct {
Message
}
func queuing(inCh chan<- Message) {
go func() {
inCh <- &fakeMessage{}
inCh <- &fakeMessage{}
time.Sleep(6 * time.Millisecond)
inCh <- &fakeMessage{}
inCh <- &fakeMessage{}
inCh <- &fakeMessage{}
inCh <- &fakeMessage{}
time.Sleep(6 * time.Millisecond)
inCh <- &fakeMessage{}
inCh <- &fakeMessage{}
close(inCh)
}()
}
func TestCreateBufferedQueue(t *testing.T) {
inCh, outCh := createBufferedQueue(
context.Background,
3,
4*time.Millisecond,
)
queuing(inCh)
for i, n := range []int{2, 3, 1, 2} {
out := <-outCh
if got, want := out.Count(), n; got != want {
t.Errorf("Item[%d] has %d messages, want %d", i, got, want)
}
}
_, ok := <-outCh
if ok {
t.Error("out channel should close")
}
}