From f8aa18cab066bf72a0f3cbbcc16f3b336bb5c1d3 Mon Sep 17 00:00:00 2001 From: tomDev5 Date: Fri, 27 Dec 2024 20:19:59 +0100 Subject: [PATCH] tcp: add retransmission exponential backoff test. --- src/socket/tcp.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index fd23f6e36..a37dbe32d 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -6411,6 +6411,38 @@ mod test { recv_nothing!(s); } + #[test] + fn test_retransmit_exponential_backoff() { + let mut s = socket_established(); + s.send_slice(b"abcdef").unwrap(); + recv!(s, time 0, Ok(TcpRepr { + seq_number: LOCAL_SEQ + 1, + ack_number: Some(REMOTE_SEQ + 1), + payload: &b"abcdef"[..], + ..RECV_TEMPL + })); + + let expected_retransmission_instant = s.rtte.retransmission_timeout().total_millis() as i64; + recv_nothing!(s, time expected_retransmission_instant - 1); + recv!(s, time expected_retransmission_instant, Ok(TcpRepr { + seq_number: LOCAL_SEQ + 1, + ack_number: Some(REMOTE_SEQ + 1), + payload: &b"abcdef"[..], + ..RECV_TEMPL + })); + + // "current time" is expected_retransmission_instant, and we want to wait 2 * retransmission timeout + let expected_retransmission_instant = 3 * expected_retransmission_instant; + + recv_nothing!(s, time expected_retransmission_instant - 1); + recv!(s, time expected_retransmission_instant, Ok(TcpRepr { + seq_number: LOCAL_SEQ + 1, + ack_number: Some(REMOTE_SEQ + 1), + payload: &b"abcdef"[..], + ..RECV_TEMPL + })); + } + // =========================================================================================// // Tests for window management. // =========================================================================================//