-
Notifications
You must be signed in to change notification settings - Fork 16
/
packet_dispatch_queue_test.go
63 lines (47 loc) · 1.26 KB
/
packet_dispatch_queue_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
57
58
59
60
61
62
63
package nex
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestReorderPackets(t *testing.T) {
pdq := NewPacketDispatchQueue()
packet1 := makePacket(2)
packet2 := makePacket(3)
packet3 := makePacket(4)
pdq.Queue(packet2)
pdq.Queue(packet3)
pdq.Queue(packet1)
result, ok := pdq.GetNextToDispatch()
assert.True(t, ok)
assert.Equal(t, packet1, result)
pdq.Dispatched(packet1)
result, ok = pdq.GetNextToDispatch()
assert.True(t, ok)
assert.Equal(t, packet2, result)
pdq.Dispatched(packet2)
result, ok = pdq.GetNextToDispatch()
assert.True(t, ok)
assert.Equal(t, packet3, result)
pdq.Dispatched(packet3)
result, ok = pdq.GetNextToDispatch()
assert.False(t, ok)
assert.Nil(t, result)
}
func TestCallingInLoop(t *testing.T) {
pdq := NewPacketDispatchQueue()
packet1 := makePacket(2)
packet2 := makePacket(3)
packet3 := makePacket(4)
pdq.Queue(packet2)
pdq.Queue(packet3)
pdq.Queue(packet1)
for nextPacket, ok := pdq.GetNextToDispatch(); ok; nextPacket, ok = pdq.GetNextToDispatch() {
pdq.Dispatched(nextPacket)
}
assert.Equal(t, uint16(5), pdq.nextExpectedSequenceId.Value)
}
func makePacket(sequenceID uint16) PRUDPPacketInterface {
packet, _ := NewPRUDPPacketV0(nil, nil, nil)
packet.SetSequenceID(sequenceID)
return packet
}