From c7a7e6b605a392eb0f54cebda58923020eb95efa Mon Sep 17 00:00:00 2001 From: Nayana Bidari Date: Fri, 14 Jul 2023 19:13:31 -0700 Subject: [PATCH] Deflake tcp test TestMaxRTO The test checked the RTO value(500ms) for the first retransmit by rounding the value to seconds which resulted in 1s. In some cases, when the RTO calculated was slightly less than 500ms (~499 ms) the test failed. Fix this by checking the absolute difference when the calculated rto is less than expected rto. Before: http://sponge2/6a8d125a-ff90-4090-8565-76b9f8a91573 After: http://sponge2/386f9716-bdc1-4079-848d-4ebc23b70167 PiperOrigin-RevId: 548273122 --- pkg/tcpip/transport/tcp/test/e2e/tcp_test.go | 9 ++++++++- 1 file changed, 8 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 e78c6a6ab..58d8cf37c 100644 --- a/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go +++ b/pkg/tcpip/transport/tcp/test/e2e/tcp_test.go @@ -4177,7 +4177,14 @@ func TestMaxRTO(t *testing.T) { checker.TCPFlagsMatch(header.TCPFlagAck, ^header.TCPFlagPsh), )) if elapsed := time.Since(start); elapsed.Round(time.Second).Seconds() != rto.Seconds() { - t.Errorf("Retransmit interval not capped to MaxRTO(%s). %s", rto, elapsed) + newRto := float64(rto / time.Millisecond) + if i == 0 { + newRto /= 2 + } + curRto := float64(elapsed.Round(time.Millisecond).Milliseconds()) + if math.Abs(newRto-curRto) > 10 { + t.Errorf("Retransmit interval not capped to RTO(%v). %v", newRto, curRto) + } } } }