@@ -45,6 +45,40 @@ func testPacketV4(proto ipproto.Proto, srcAddr, dstAddr [4]byte, srcPort, dstPor
45
45
return append (out , make ([]byte , int (size )- len (out ))... )
46
46
}
47
47
48
+ // TestInterval ensures that we receive at least one call to `dump` using only
49
+ // maxPeriod.
50
+ func TestInterval (t * testing.T ) {
51
+ c := qt .New (t )
52
+
53
+ const maxPeriod = 10 * time .Millisecond
54
+ const maxConns = 2048
55
+
56
+ gotDump := make (chan struct {}, 1 )
57
+ stats := NewStatistics (maxPeriod , maxConns , func (_ , _ time.Time , _ , _ map [netlogtype.Connection ]netlogtype.Counts ) {
58
+ select {
59
+ case gotDump <- struct {}{}:
60
+ default :
61
+ }
62
+ })
63
+ defer stats .Shutdown (context .Background ())
64
+
65
+ srcAddr := netip .AddrFrom4 ([4 ]byte {192 , 168 , 0 , byte (rand .Intn (16 ))})
66
+ dstAddr := netip .AddrFrom4 ([4 ]byte {192 , 168 , 0 , byte (rand .Intn (16 ))})
67
+ srcPort := uint16 (rand .Intn (16 ))
68
+ dstPort := uint16 (rand .Intn (16 ))
69
+ size := uint16 (64 + rand .Intn (1024 ))
70
+ p := testPacketV4 (ipproto .TCP , srcAddr .As4 (), dstAddr .As4 (), srcPort , dstPort , size )
71
+ stats .UpdateRxVirtual (p )
72
+
73
+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
74
+ defer cancel ()
75
+ select {
76
+ case <- ctx .Done ():
77
+ c .Fatal ("didn't receive dump within context deadline" )
78
+ case <- gotDump :
79
+ }
80
+ }
81
+
48
82
func TestConcurrent (t * testing.T ) {
49
83
flakytest .Mark (t , "https://github.com/tailscale/tailscale/issues/7030" )
50
84
c := qt .New (t )
0 commit comments