-
Notifications
You must be signed in to change notification settings - Fork 3
/
slice_chan_interface_test.go
51 lines (40 loc) · 981 Bytes
/
slice_chan_interface_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
50
51
package concurrent
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSliceChanInterface(t *testing.T) {
s := NewSliceChanInterface()
ch := make(chan interface{}, 5)
s.Add(ch)
assert.Equal(t, 1, s.Len())
ch2 := make(chan interface{}, 5)
s.Add(ch2)
assert.Equal(t, 2, s.Len())
ch3 := make(chan interface{}, 5)
s.Add(ch3)
assert.Equal(t, 3, s.Len())
ch4 := make(chan interface{}, 5)
s.Add(ch4)
assert.Equal(t, 4, s.Len())
str := "bla"
s.Send(str)
// TODO: remove?
time.Sleep(200 * time.Millisecond)
assert.Equal(t, len(ch), 1)
assert.Equal(t, len(ch2), 1)
assert.Equal(t, len(ch3), 1)
assert.Equal(t, len(ch3), 1)
assert.Equal(t, len(ch4), 1)
assert.Equal(t, str, <-ch)
assert.Equal(t, str, <-ch2)
assert.Equal(t, str, <-ch3)
assert.Equal(t, str, <-ch4)
assert.True(t, s.Remove(ch2))
assert.Equal(t, 3, s.Len())
assert.True(t, s.Remove(ch4))
assert.Equal(t, 2, s.Len())
s.RemoveAll()
assert.Equal(t, 0, s.Len())
}