forked from ProtonMail/tobubus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsessionmanager_test.go
49 lines (44 loc) · 1.18 KB
/
sessionmanager_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 tobubus
import (
"testing"
)
func TestGetUniqueSessionWithRecycleStrategy(t *testing.T) {
manager := newSessionManager(recycleStrategy)
if id := manager.getUniqueSessionID(); id != 0 {
t.Errorf("expected 0, but %d", id)
}
if id := manager.getUniqueSessionID(); id != 1 {
t.Errorf("expected 1, but %d", id)
}
if id := manager.getUniqueSessionID(); id != 2 {
t.Errorf("expected 2, but %d", id)
}
go func() {
channel := manager.getChannelOfSessionID(1)
channel <- nil
}()
manager.receiveAndClose(1)
if id := manager.getUniqueSessionID(); id != 1 {
t.Errorf("expected 1, but %d", id)
}
}
func TestGetUniqueSessionWithIncrementStrategy(t *testing.T) {
manager := newSessionManager(incrementStrategy)
if id := manager.getUniqueSessionID(); id != 0 {
t.Errorf("expected 0, but %d", id)
}
if id := manager.getUniqueSessionID(); id != 1 {
t.Errorf("expected 1, but %d", id)
}
if id := manager.getUniqueSessionID(); id != 2 {
t.Errorf("expected 2, but %d", id)
}
go func() {
channel := manager.getChannelOfSessionID(1)
channel <- nil
}()
manager.receiveAndClose(1)
if id := manager.getUniqueSessionID(); id != 3 {
t.Errorf("expected 3, but %d", id)
}
}