forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_timer_test.go
60 lines (48 loc) · 1.87 KB
/
connection_timer_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
package quic
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func (t *connectionTimer) Deadline() time.Time { return t.timer.Deadline() }
func TestConnectionTimerModes(t *testing.T) {
now := time.Now()
t.Run("idle timeout", func(t *testing.T) {
timer := newTimer()
timer.SetTimer(now.Add(time.Hour), time.Time{}, time.Time{}, time.Time{})
require.Equal(t, now.Add(time.Hour), timer.Deadline())
})
t.Run("ACK timer", func(t *testing.T) {
timer := newTimer()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
require.Equal(t, now.Add(time.Minute), timer.Deadline())
})
t.Run("loss timer", func(t *testing.T) {
timer := newTimer()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), time.Time{})
require.Equal(t, now.Add(time.Second), timer.Deadline())
})
t.Run("pacing timer", func(t *testing.T) {
timer := newTimer()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), now.Add(time.Millisecond))
require.Equal(t, now.Add(time.Millisecond), timer.Deadline())
})
}
func TestConnectionTimerReset(t *testing.T) {
now := time.Now()
timer := newTimer()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
require.Equal(t, now.Add(time.Minute), timer.Deadline())
timer.SetRead()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
require.Equal(t, now.Add(time.Hour), timer.Deadline())
}
func TestConnectionTimerSendImmediately(t *testing.T) {
now := time.Now()
timer := newTimer()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
require.Equal(t, now.Add(time.Minute), timer.Deadline())
timer.SetRead()
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, deadlineSendImmediately)
require.Equal(t, deadlineSendImmediately, timer.Deadline())
}