forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession_map_test.go
56 lines (48 loc) · 1.35 KB
/
session_map_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
52
53
54
55
56
package quic
import (
"time"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Session Handler", func() {
var handler *sessionMap
BeforeEach(func() {
handler = newSessionMap().(*sessionMap)
})
It("adds and gets", func() {
connID := protocol.ConnectionID{1, 2, 3, 4, 5}
sess := &mockSession{}
handler.Add(connID, sess)
session, ok := handler.Get(connID)
Expect(ok).To(BeTrue())
Expect(session).To(Equal(sess))
})
It("deletes", func() {
connID := protocol.ConnectionID{1, 2, 3, 4, 5}
handler.Add(connID, &mockSession{})
handler.Remove(connID)
session, ok := handler.Get(connID)
Expect(ok).To(BeTrue())
Expect(session).To(BeNil())
})
It("deletes nil session entries after a wait time", func() {
handler.deleteClosedSessionsAfter = 25 * time.Millisecond
connID := protocol.ConnectionID{1, 2, 3, 4, 5}
handler.Add(connID, &mockSession{})
handler.Remove(connID)
Eventually(func() bool {
_, ok := handler.Get(connID)
return ok
}).Should(BeFalse())
})
It("closes", func() {
sess1 := NewMockPacketHandler(mockCtrl)
sess1.EXPECT().Close(nil)
sess2 := NewMockPacketHandler(mockCtrl)
sess2.EXPECT().Close(nil)
handler.Add(protocol.ConnectionID{1, 1, 1, 1}, sess1)
handler.Add(protocol.ConnectionID{2, 2, 2, 2}, sess2)
handler.Close()
})
})