From b9f04e4000a9668f3528af2e590c5b23254a7125 Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Wed, 31 Aug 2022 13:37:01 -0700 Subject: [PATCH] Refactor TestHandshakeTimeoutConnectCount to use a fake clock. This makes the test take 2 seconds instead of 2+ minutes. PiperOrigin-RevId: 471341662 --- pkg/tcpip/transport/tcp/test/e2e/tcp_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go b/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go index 6776a05a2..3cdcda86c 100644 --- a/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go +++ b/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go @@ -293,7 +293,13 @@ func TestCloseWithoutConnect(t *testing.T) { } func TestHandshakeTimeoutConnectedCount(t *testing.T) { - c := context.New(t, e2e.DefaultMTU) + clock := faketime.NewManualClock() + c := context.NewWithOpts(t, context.Options{ + EnableV4: true, + EnableV6: true, + MTU: e2e.DefaultMTU, + Clock: clock, + }) defer c.Cleanup() ep, err := c.Stack().NewEndpoint(tcp.ProtocolNumber, ipv4.ProtocolNumber, &c.WQ) @@ -312,6 +318,8 @@ func TestHandshakeTimeoutConnectedCount(t *testing.T) { t.Fatalf("Connect did not start: %v", err) } + clock.Advance(tcp.DefaultKeepaliveInterval) + clock.Advance(tcp.DefaultKeepaliveInterval) <-ch switch err := c.EP.LastError().(type) { case *tcpip.ErrTimeout: