diff options
author | Zeling Feng <zeling@google.com> | 2021-08-25 16:32:16 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-08-25 16:41:48 -0700 |
commit | 4c7aaa941eaa05eea99b1b1e7f8e33b42c2bd6a8 (patch) | |
tree | 2136419ec54417d1883c2a6c3fe2fff6e24a47b0 /pkg/tcpip/transport | |
parent | aa2d07442c8760e2b60c4fa0e403657f2fe318e4 (diff) |
Improve TestTimestampSynCookies
.. by advancing the clock so that NowMonotonic does not return 0.
PiperOrigin-RevId: 393005373
Diffstat (limited to 'pkg/tcpip/transport')
-rw-r--r-- | pkg/tcpip/transport/tcp/tcp_test.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/pkg/tcpip/transport/tcp/tcp_test.go b/pkg/tcpip/transport/tcp/tcp_test.go index bf726e86a..36bc638a8 100644 --- a/pkg/tcpip/transport/tcp/tcp_test.go +++ b/pkg/tcpip/transport/tcp/tcp_test.go @@ -8221,6 +8221,11 @@ func TestSendBufferTuning(t *testing.T) { func TestTimestampSynCookies(t *testing.T) { clock := faketime.NewManualClock() + tsNow := func() uint32 { + return uint32(clock.NowMonotonic().Sub(tcpip.MonotonicTime{}).Milliseconds()) + } + // Advance the clock so that NowMonotonic is non-zero. + clock.Advance(time.Second) c := context.NewWithOpts(t, context.Options{ EnableV4: true, EnableV6: true, @@ -8261,6 +8266,8 @@ func TestTimestampSynCookies(t *testing.T) { tcpHdr := header.TCP(header.IPv4(b).Payload()) c.IRS = seqnum.Value(tcpHdr.SequenceNumber()) initialTSVal := tcpHdr.ParsedOptions().TSVal + // derive the tsOffset. + tsOffset := initialTSVal - tsNow() header.EncodeTSOption(420, initialTSVal, tcpOpts[2:]) c.SendPacket(nil, &context.Headers{ @@ -8293,8 +8300,8 @@ func TestTimestampSynCookies(t *testing.T) { t.Fatalf("failed to accept: %s", err) } - const elapsed = 200 * time.Millisecond - clock.Advance(elapsed) + // Advance the clock again so that we expect the next TSVal to change. + clock.Advance(time.Second) data := []byte{1, 2, 3} var r bytes.Reader r.Reset(data) @@ -8304,7 +8311,7 @@ func TestTimestampSynCookies(t *testing.T) { // The endpoint should have a correct TSOffset so that the received TSVal // should match our expectation. - if got, want := header.TCP(header.IPv4(c.GetPacket()).Payload()).ParsedOptions().TSVal, initialTSVal+uint32(elapsed.Milliseconds()); got != want { + if got, want := header.TCP(header.IPv4(c.GetPacket()).Payload()).ParsedOptions().TSVal, tsNow()+tsOffset; got != want { t.Fatalf("got TSVal = %d, want %d", got, want) } } |