in quic/s2n-quic-transport/src/recovery/manager/tests.rs [1751:1863]
fn detect_lost_packets_persistent_congestion_path_aware() {
// Setup:
let space = PacketNumberSpace::ApplicationData;
let mut publisher = Publisher::snapshot();
let (_first_addr, first_path_id, _second_addr, second_path_id, mut manager, mut path_manager) =
helper_generate_multi_path_manager(space, &mut publisher);
let ecn = ExplicitCongestionNotification::default();
let mut context = MockContext::new(&mut path_manager);
let mut now = time::now();
manager.largest_acked_packet = Some(space.new_packet_number(VarInt::from_u8(20)));
// create first rtt samples so they can enter enter persistent_congestion
context
.path_mut_by_id(first_path_id)
.rtt_estimator
.update_rtt(
Duration::from_secs(0),
Duration::from_secs(8),
now,
true,
space,
);
context
.path_mut_by_id(second_path_id)
.rtt_estimator
.update_rtt(
Duration::from_secs(0),
Duration::from_secs(8),
now,
true,
space,
);
// Trigger:
let outcome = transmission::Outcome {
ack_elicitation: AckElicitation::Eliciting,
is_congestion_controlled: true,
bytes_sent: 1,
bytes_progressed: 0,
};
// Send a packet that was sent too long ago (lost)
for i in 1..=2 {
now += Duration::from_secs(1);
manager.on_packet_sent(
space.new_packet_number(VarInt::from_u8(i)),
outcome,
now,
ecn,
transmission::Mode::Normal,
None,
&mut context,
&mut publisher,
);
}
// Send a packet that was sent too long ago (lost)
for i in 3..=6 {
now += Duration::from_secs(1);
context.set_path_id(second_path_id);
manager.on_packet_sent(
space.new_packet_number(VarInt::from_u8(i)),
outcome,
now,
ecn,
transmission::Mode::Normal,
None,
&mut context,
&mut publisher,
);
}
// Send a packet that was sent too long ago (lost)
for i in 7..=9 {
now += Duration::from_secs(1);
context.set_path_id(first_path_id);
manager.on_packet_sent(
space.new_packet_number(VarInt::from_u8(i)),
outcome,
now,
ecn,
transmission::Mode::Normal,
None,
&mut context,
&mut publisher,
);
}
// increase the time so all sent packets will be considered lost
now += Duration::from_secs(10);
let expected_time_threshold = Duration::from_secs(9);
assert_eq!(
expected_time_threshold,
context
.path_by_id(first_path_id)
.rtt_estimator
.loss_time_threshold(),
);
// 1-9 packets packets sent, each size 1 byte
let bytes_in_flight: u16 = manager
.sent_packets
.iter()
.map(|(_, info)| info.sent_bytes)
.sum();
assert_eq!(bytes_in_flight, 9);
let (max_persistent_congestion_period, _sent_packets_to_remove) =
manager.detect_lost_packets(now, &mut context, &mut publisher);
// Expectation:
assert_eq!(max_persistent_congestion_period, Duration::from_secs(2));
}