-
Notifications
You must be signed in to change notification settings - Fork 12
/
session_change_lists_test.go
48 lines (40 loc) · 1.49 KB
/
session_change_lists_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
package enigma
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSessionChangeLists(t *testing.T) {
// Set up two channels - on for all change lists, and one for all
s := newSessionChangeLists()
allChangeListsChannel := s.ChangeListsChannel(false)
pushedChangeListsChannel := s.ChangeListsChannel(true)
// Emit two lists
s.emitChangeLists([]int{1, 2}, []int{3, 4}, []int{9, 10}, true)
s.emitChangeLists([]int{5, 6}, []int{7, 8}, []int{11, 12}, false)
// Check that the lists appear as expected
allData1 := <-allChangeListsChannel
allData2 := <-allChangeListsChannel
assert.Equal(t, 1, allData1.Changed[0])
assert.Equal(t, 3, allData1.Closed[0])
assert.Equal(t, 9, allData1.Suspended[0])
assert.Equal(t, 5, allData2.Changed[0])
assert.Equal(t, 7, allData2.Closed[0])
assert.Equal(t, 11, allData2.Suspended[0])
pushedData1 := <-pushedChangeListsChannel
assert.Equal(t, 1, pushedData1.Changed[0])
assert.Equal(t, 3, pushedData1.Closed[0])
assert.Equal(t, 9, pushedData1.Suspended[0])
// Check that the second non-pushed list doesn't appear
var nothingInChangePushedChangeList bool
select {
case <-pushedChangeListsChannel:
nothingInChangePushedChangeList = false
default:
nothingInChangePushedChangeList = true
}
assert.True(t, nothingInChangePushedChangeList)
// Close listeners are check that they are actually deregistered
s.CloseChangeListsChannel(pushedChangeListsChannel)
s.CloseChangeListsChannel(allChangeListsChannel)
assert.Equal(t, len(s.channels), 0)
}