-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquic_client_initial_test.go
76 lines (64 loc) · 1.5 KB
/
quic_client_initial_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
71
72
73
74
75
76
package clienthellod_test
import (
"runtime"
"testing"
"time"
. "github.com/gaukas/clienthellod"
)
var mapGatheredClientInitials = map[string][][]byte{
"Chrome125": {
quicIETFData_Chrome125_PKN1,
quicIETFData_Chrome125_PKN2,
},
"Firefox126": {
quicIETFData_Firefox126,
},
"Firefox126_0-RTT": {
quicIETFData_Firefox126_0_RTT,
},
}
func TestGatherClientInitials(t *testing.T) {
for name, test := range mapGatheredClientInitials {
t.Run(name, func(t *testing.T) {
testGatherClientInitialsWithRawPayload(t, test)
})
}
}
func testGatherClientInitialsWithRawPayload(t *testing.T, data [][]byte) {
until := time.Now().Add(1 * time.Second) // must be gathered within 1 second
ci := GatherClientInitialsWithDeadline(until)
for _, d := range data {
cip, err := UnmarshalQUICClientInitialPacket(d)
if err != nil {
t.Fatal(err)
}
err = ci.AddPacket(cip)
if err != nil {
t.Fatal(err)
}
}
if !ci.Completed() {
t.Fatalf("GatheredClientInitials is not completed")
}
}
func TestGatheredClientInitialsGC(t *testing.T) {
gcOk := make(chan bool, 1)
gci := GatherClientInitials()
// Use a dummy ClientHello to detect if the GatheredClientInitials is GCed
dummyClientHello := &QUICClientHello{}
gci.ClientHello = dummyClientHello
runtime.SetFinalizer(dummyClientHello, func(c *QUICClientHello) {
close(gcOk)
})
gcCnt := 0
for gcCnt < 5 {
select {
case <-gcOk:
return
default:
runtime.GC()
gcCnt++
}
}
t.Fatalf("GatheredClientInitials is not GCed within 5 cycles")
}