forked from gortc/ice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent_transaction_test.go
69 lines (66 loc) · 1.19 KB
/
agent_transaction_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
package ice
import (
"testing"
"time"
"github.com/gortc/stun"
)
func TestAgent_Timeout(t *testing.T) {
t.Run("NoRetry", func(t *testing.T) {
a, err := NewAgent()
if err != nil {
t.Fatal(err)
}
a.checklist = 0
a.set = ChecklistSet{
{
Pairs: Pairs{
{},
},
},
}
now := time.Now()
at := &agentTransaction{
id: stun.NewTransactionID(),
rto: time.Millisecond * 100,
start: now,
attempt: 1,
maxAttempts: 1,
pair: getPairKey(&a.set[0].Pairs[0]),
}
a.t[at.id] = at
a.collect(at.deadline)
_, ok := a.t[at.id]
if ok {
t.Error("transaction should be removed")
}
})
t.Run("Retry", func(t *testing.T) {
a, err := NewAgent()
if err != nil {
t.Fatal(err)
}
a.checklist = 0
a.set = ChecklistSet{
{
Pairs: Pairs{
{},
},
},
}
now := time.Now()
at := &agentTransaction{
id: stun.NewTransactionID(),
rto: time.Millisecond * 100,
start: now,
attempt: 2,
maxAttempts: 3,
pair: getPairKey(&a.set[0].Pairs[0]),
}
a.t[at.id] = at
a.collect(at.deadline)
_, ok := a.t[at.id]
if !ok {
t.Error("transaction should be kept")
}
})
}