-
Notifications
You must be signed in to change notification settings - Fork 16
/
tracking_test.go
70 lines (61 loc) · 2.01 KB
/
tracking_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
64
65
66
67
68
69
70
package minq
import (
"fmt"
"github.com/bifurcation/mint"
"runtime"
"testing"
)
type testTrackingFixture struct {
pns []uint64
r *recvdPackets
}
func newTestTrackingFixture() *testTrackingFixture {
pc, _, _, ok := runtime.Caller(1)
name := "unknown"
if ok {
name = runtime.FuncForPC(pc).Name()
}
log := func(tag string, format string, args ...interface{}) {
fullFormat := fmt.Sprintf("%s: %s", name, format)
logf(tag, fullFormat, args...)
}
pns := make([]uint64, 10)
for i := uint64(0); i < 10; i++ {
pns[i] = uint64(0xdead0000) + i
}
return &testTrackingFixture{
pns,
newRecvdPackets(log),
}
}
func TestTrackingPacketsReceived(t *testing.T) {
f := newTestTrackingFixture()
assertEquals(t, true, f.r.packetNotReceived(f.pns[1]))
f.r.init(f.pns[0])
assertEquals(t, true, f.r.packetNotReceived(f.pns[0]))
assertEquals(t, true, f.r.packetNotReceived(f.pns[1]))
f.r.packetSetReceived(f.pns[0], false, true)
assertEquals(t, false, f.r.packetNotReceived(f.pns[0]))
assertEquals(t, true, f.r.packetNotReceived(f.pns[1]))
f.r.packetSetReceived(f.pns[1], true, true)
assertEquals(t, false, f.r.packetNotReceived(f.pns[1]))
// Check that things less than min are received
assertEquals(t, false, f.r.packetNotReceived(f.pns[0]-1))
// Now make some ACKs
ar := f.r.prepareAckRange(mint.EpochApplicationData, false)
assertX(t, len(ar) == 1, "Should be one entry in ACK range")
assertEquals(t, ar[0].lastPacket, f.pns[1])
assertEquals(t, ar[0].count, uint64(2))
f.r.packetSetReceived(f.pns[3], true, true)
ar = f.r.prepareAckRange(mint.EpochApplicationData, false)
assertX(t, len(ar) == 2, "Should be two entry in ACK range")
assertEquals(t, ar[0].lastPacket, f.pns[3])
assertEquals(t, ar[1].lastPacket, f.pns[1])
assertEquals(t, ar[1].count, uint64(2))
// Now ack all the acks, so that we should send nothing.
f.r.packetSetAcked2(f.pns[0])
f.r.packetSetAcked2(f.pns[1])
f.r.packetSetAcked2(f.pns[3])
ar = f.r.prepareAckRange(mint.EpochApplicationData, false)
assertX(t, len(ar) == 0, "Should be no acks")
}