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
This commit is contained in:
Nayana Bidari
2023-07-14 19:15:49 -07:00
committed by gVisor bot
parent e54e3668b0
commit c7a7e6b605
+8 -1
View File
@@ -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)
}
}
}
}