fn drop_spaces()

in neqo-transport/src/recovery/mod.rs [1386:1468]


    fn drop_spaces() {
        let mut lr = Fixture::default();
        lr.on_packet_sent(
            SentPacket::new(
                PacketType::Initial,
                0,
                pn_time(0),
                true,
                Vec::new(),
                ON_SENT_SIZE,
            ),
            Instant::now(),
        );
        lr.on_packet_sent(
            SentPacket::new(
                PacketType::Handshake,
                0,
                pn_time(1),
                true,
                Vec::new(),
                ON_SENT_SIZE,
            ),
            Instant::now(),
        );
        lr.on_packet_sent(
            SentPacket::new(
                PacketType::Short,
                0,
                pn_time(2),
                true,
                Vec::new(),
                ON_SENT_SIZE,
            ),
            Instant::now(),
        );

        // Now put all spaces on the LR timer so we can see them.
        for sp in &[
            PacketType::Initial,
            PacketType::Handshake,
            PacketType::Short,
        ] {
            let sent_pkt = SentPacket::new(*sp, 1, pn_time(3), true, Vec::new(), ON_SENT_SIZE);
            let pn_space = PacketNumberSpace::from(sent_pkt.packet_type());
            lr.on_packet_sent(sent_pkt, Instant::now());
            lr.on_ack_received(
                pn_space,
                vec![1..=1],
                None,
                Duration::from_secs(0),
                pn_time(3),
            );
            let mut lost = Vec::new();
            lr.spaces.get_mut(pn_space).unwrap().detect_lost_packets(
                pn_time(3),
                TEST_RTT,
                TEST_RTT * 3, // unused
                &mut lost,
            );
            assert!(lost.is_empty());
        }

        lr.discard(PacketNumberSpace::Initial, pn_time(3));
        assert_sent_times(&lr, None, Some(pn_time(1)), Some(pn_time(2)));

        lr.discard(PacketNumberSpace::Handshake, pn_time(3));
        assert_sent_times(&lr, None, None, Some(pn_time(2)));

        // There are cases where we send a packet that is not subsequently tracked.
        // So check that this works.
        lr.on_packet_sent(
            SentPacket::new(
                PacketType::Initial,
                0,
                pn_time(3),
                true,
                Vec::new(),
                ON_SENT_SIZE,
            ),
            Instant::now(),
        );
        assert_sent_times(&lr, None, None, Some(pn_time(2)));
    }