forked from eapache/channels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverflowing_channel_test.go
49 lines (42 loc) · 1.07 KB
/
overflowing_channel_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
47
48
49
package channels
import "testing"
func TestOverflowingChannel(t *testing.T) {
var ch Channel
ch = NewOverflowingChannel(Infinity) // yes this is rather silly, but it should work
testChannel(t, "infinite overflowing channel", ch)
ch = NewOverflowingChannel(None)
go func() {
for i := 0; i < 1000; i++ {
ch.In() <- i
}
ch.Close()
}()
prev := -1
for i := range ch.Out() {
if prev >= i.(int) {
t.Fatal("overflowing channel prev", prev, "but got", i.(int))
}
}
ch = NewOverflowingChannel(10)
for i := 0; i < 1000; i++ {
ch.In() <- i
}
ch.Close()
for i := 0; i < 10; i++ {
val := <-ch.Out()
if i != val.(int) {
t.Fatal("overflowing channel expected", i, "but got", val.(int))
}
}
if val, open := <-ch.Out(); open == true {
t.Fatal("overflowing channel expected closed but got", val)
}
ch = NewOverflowingChannel(None)
ch.In() <- 0
ch.Close()
if val, open := <-ch.Out(); open == true {
t.Fatal("overflowing channel expected closed but got", val)
}
ch = NewOverflowingChannel(2)
testChannelConcurrentAccessors(t, "overflowing channel", ch)
}