Ack Cut 3: the flow-window tests shake hands the way Cut 1 requires
An Accept now counts only while the session's own Connect awaits it, and reliable data is refused until the handshake seeds the watermark, so the tests' bare Accept no longer connected the session. The helpers now pair a sender and a receiver through CreateConnect/AcceptConnect in all four runtimes; the sender's Connect is acknowledged, so nothing is pending on it when the tests begin. Rust also takes initial_sequence as an Option. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8c71b5c6dd
commit
ede87f7423
4 changed files with 69 additions and 43 deletions
|
|
@ -882,12 +882,23 @@ class CultNetTests(unittest.TestCase):
|
|||
FLOW_CONNECTION_ID = 0x464C4F57
|
||||
MIB = 1024 * 1024
|
||||
|
||||
def _connected_flow_session(self, initial_sequence: int) -> CultNetRudpSession:
|
||||
session = CultNetRudpSession(
|
||||
def _flow_session(self, initial_sequence: int) -> CultNetRudpSession:
|
||||
return CultNetRudpSession(
|
||||
CultNetRudpSessionOptions(connection_id=self.FLOW_CONNECTION_ID, initial_sequence=initial_sequence)
|
||||
)
|
||||
session.receive(CultNetRudpPacket(CultNetRudpPacketType.ACCEPT, self.FLOW_CONNECTION_ID, 0, 0, 0, "control"))
|
||||
return session
|
||||
|
||||
def _connected_flow_pair(
|
||||
self, sender_initial_sequence: int, receiver_initial_sequence: int
|
||||
) -> tuple[CultNetRudpSession, CultNetRudpSession]:
|
||||
"""A sender and a receiver that have shaken hands: the receiver's watermark is seeded by the sender's
|
||||
Connect, and the sender's Connect is acknowledged, so nothing is pending on the sender."""
|
||||
sender = self._flow_session(sender_initial_sequence)
|
||||
receiver = self._flow_session(receiver_initial_sequence)
|
||||
sender.receive(receiver.accept_connect(sender.create_connect(0), 0), 0)
|
||||
return sender, receiver
|
||||
|
||||
def _connected_flow_session(self, initial_sequence: int) -> CultNetRudpSession:
|
||||
return self._connected_flow_pair(initial_sequence, 900)[0]
|
||||
|
||||
@staticmethod
|
||||
def _flow_send(session: CultNetRudpSession, payload_bytes: int) -> tuple[CultNetRudpPacket, ...]:
|
||||
|
|
@ -904,8 +915,7 @@ class CultNetTests(unittest.TestCase):
|
|||
return g
|
||||
|
||||
def test_cultnet_rudp_a_lost_packet_holds_the_sender_1023_sequences_ahead_and_is_still_delivered(self) -> None:
|
||||
sender = self._connected_flow_session(1)
|
||||
receiver = self._connected_flow_session(100)
|
||||
sender, receiver = self._connected_flow_pair(1, 100)
|
||||
g = self._flow_send(sender, 1)[0]
|
||||
admitted_after_g = 0
|
||||
for _ in range(4200):
|
||||
|
|
|
|||
|
|
@ -8,32 +8,32 @@ use cultnet_rs::*;
|
|||
const CONNECTION_ID: u32 = 0x464c_4f57;
|
||||
const MIB: usize = 1024 * 1024;
|
||||
|
||||
fn connected(initial_sequence: u32) -> Result<CultNetRudpSession> {
|
||||
let mut session = CultNetRudpSession::new(CultNetRudpSessionOptions {
|
||||
fn session(initial_sequence: u32) -> CultNetRudpSession {
|
||||
CultNetRudpSession::new(CultNetRudpSessionOptions {
|
||||
connection_id: CONNECTION_ID,
|
||||
initial_sequence,
|
||||
initial_sequence: Some(initial_sequence),
|
||||
resend_delay_ms: 25,
|
||||
max_pending_reliable_packets: None,
|
||||
});
|
||||
session.receive(
|
||||
&CultNetRudpPacket {
|
||||
packet_type: CultNetRudpPacketType::Accept,
|
||||
connection_id: CONNECTION_ID,
|
||||
sequence: 0,
|
||||
ack: 0,
|
||||
ack_mask: 0,
|
||||
channel_id: "control".into(),
|
||||
reliable: false,
|
||||
ordered: false,
|
||||
sequenced: false,
|
||||
fragment_id: 0,
|
||||
fragment_index: 0,
|
||||
fragment_count: 0,
|
||||
payload: Vec::new(),
|
||||
},
|
||||
0,
|
||||
)?;
|
||||
Ok(session)
|
||||
})
|
||||
}
|
||||
|
||||
/// A sender and a receiver that have shaken hands: the receiver's watermark is
|
||||
/// seeded by the sender's Connect, and the sender's Connect is acknowledged, so
|
||||
/// nothing is pending on the sender.
|
||||
fn connected_pair(
|
||||
sender_initial_sequence: u32,
|
||||
receiver_initial_sequence: u32,
|
||||
) -> Result<(CultNetRudpSession, CultNetRudpSession)> {
|
||||
let mut sender = session(sender_initial_sequence);
|
||||
let mut receiver = session(receiver_initial_sequence);
|
||||
let connect = sender.create_connect(0, Vec::new())?;
|
||||
let accept = receiver.accept_connect(&connect, 0, Vec::new())?;
|
||||
sender.receive(&accept, 0)?;
|
||||
Ok((sender, receiver))
|
||||
}
|
||||
|
||||
fn connected(initial_sequence: u32) -> Result<CultNetRudpSession> {
|
||||
Ok(connected_pair(initial_sequence, 900)?.0)
|
||||
}
|
||||
|
||||
fn reliable() -> CultNetRudpSendOptions {
|
||||
|
|
@ -84,8 +84,7 @@ fn lose_g_and_fill_the_span(session: &mut CultNetRudpSession) -> Result<CultNetR
|
|||
|
||||
#[test]
|
||||
fn a_lost_packet_holds_the_sender_1023_sequences_ahead_and_is_still_delivered() -> Result<()> {
|
||||
let mut sender = connected(1)?;
|
||||
let mut receiver = connected(100)?;
|
||||
let (mut sender, mut receiver) = connected_pair(1, 100)?;
|
||||
let g = send(&mut sender, 1)?.remove(0);
|
||||
// g is lost. Everything after it is delivered and acked, until the sender stops.
|
||||
let mut admitted_after_g = 0u32;
|
||||
|
|
|
|||
|
|
@ -1421,10 +1421,21 @@ test("rudp session advances large fragment sets through a bounded reliable windo
|
|||
const FLOW_CONNECTION_ID = 0x464c4f57;
|
||||
const MIB = 1024 * 1024;
|
||||
|
||||
function flowSession(initialSequence: number): CultNetRudpSession {
|
||||
return new CultNetRudpSession({ connectionId: FLOW_CONNECTION_ID, initialSequence, resendDelayMs: 25 });
|
||||
}
|
||||
|
||||
// A sender and a receiver that have shaken hands: the receiver's watermark is seeded by the sender's Connect, and the
|
||||
// sender's Connect is acknowledged, so nothing is pending on the sender.
|
||||
function connectedFlowPair(senderInitialSequence: number, receiverInitialSequence: number): [CultNetRudpSession, CultNetRudpSession] {
|
||||
const sender = flowSession(senderInitialSequence);
|
||||
const receiver = flowSession(receiverInitialSequence);
|
||||
sender.receive(receiver.acceptConnect(sender.createConnect(0), 0), 0);
|
||||
return [sender, receiver];
|
||||
}
|
||||
|
||||
function connectedFlowSession(initialSequence: number): CultNetRudpSession {
|
||||
const session = new CultNetRudpSession({ connectionId: FLOW_CONNECTION_ID, initialSequence, resendDelayMs: 25 });
|
||||
session.receive({ packetType: "accept", connectionId: FLOW_CONNECTION_ID, sequence: 0, ack: 0, ackMask: 0, channelId: "control" });
|
||||
return session;
|
||||
return connectedFlowPair(initialSequence, 900)[0];
|
||||
}
|
||||
|
||||
function flowSend(session: CultNetRudpSession, payloadBytes: number): CultNetRudpPacket[] {
|
||||
|
|
@ -1447,8 +1458,7 @@ function loseGAndFillTheSpan(session: CultNetRudpSession): CultNetRudpPacket {
|
|||
}
|
||||
|
||||
test("a lost packet holds the sender 1023 sequences ahead and is still delivered", () => {
|
||||
const sender = connectedFlowSession(1);
|
||||
const receiver = connectedFlowSession(100);
|
||||
const [sender, receiver] = connectedFlowPair(1, 100);
|
||||
const g = flowSend(sender, 1)[0]!;
|
||||
let admittedAfterG = 0;
|
||||
for (let index = 0; index < 4200; index++) {
|
||||
|
|
|
|||
|
|
@ -1145,18 +1145,26 @@ namespace GameCult.Networking.Tests
|
|||
// above the lowest unacked one and the payload above that sequence stays within 4 MiB.
|
||||
private const int Mib = 1024 * 1024;
|
||||
|
||||
private static CultNetRudpSession ConnectedFlowSession(uint initialSequence)
|
||||
{
|
||||
var session = new CultNetRudpSession(new CultNetRudpSessionOptions
|
||||
private static CultNetRudpSession FlowSession(uint initialSequence) =>
|
||||
new CultNetRudpSession(new CultNetRudpSessionOptions
|
||||
{
|
||||
ConnectionId = 0x464c4f57,
|
||||
InitialSequence = initialSequence,
|
||||
ResendDelayMs = 25
|
||||
});
|
||||
session.Receive(new CultNetRudpPacket { PacketType = CultNetRudpPacketType.Accept, ConnectionId = 0x464c4f57, Sequence = 0, ChannelId = "control" });
|
||||
return session;
|
||||
|
||||
// A sender and a receiver that have shaken hands: the receiver's watermark is seeded by the sender's
|
||||
// Connect, and the sender's Connect is acknowledged, so nothing is pending on the sender.
|
||||
private static (CultNetRudpSession Sender, CultNetRudpSession Receiver) ConnectedFlowPair(uint senderInitialSequence, uint receiverInitialSequence)
|
||||
{
|
||||
var sender = FlowSession(senderInitialSequence);
|
||||
var receiver = FlowSession(receiverInitialSequence);
|
||||
sender.Receive(receiver.AcceptConnect(sender.CreateConnect(0), 0), 0);
|
||||
return (sender, receiver);
|
||||
}
|
||||
|
||||
private static CultNetRudpSession ConnectedFlowSession(uint initialSequence) => ConnectedFlowPair(initialSequence, 900).Sender;
|
||||
|
||||
private static IReadOnlyList<CultNetRudpPacket> FlowSend(CultNetRudpSession session, int payloadBytes) =>
|
||||
session.SendMany("state", new byte[payloadBytes], new CultNetRudpSendOptions { Reliable = true });
|
||||
|
||||
|
|
@ -1177,8 +1185,7 @@ namespace GameCult.Networking.Tests
|
|||
[Test]
|
||||
public void RudpSession_ALostPacketHoldsTheSender1023SequencesAheadAndIsStillDelivered()
|
||||
{
|
||||
var sender = ConnectedFlowSession(1);
|
||||
var receiver = ConnectedFlowSession(100);
|
||||
var (sender, receiver) = ConnectedFlowPair(1, 100);
|
||||
var g = FlowSend(sender, 1).Single();
|
||||
var admittedAfterG = 0;
|
||||
for (var index = 0; index < 4200; index++)
|
||||
|
|
|
|||
Loading…
Reference in a new issue