cultmesh-rs tests: the scripted peer reports that it has stalled (stall-proven-by-sleep)
peer.stall() now returns once the peer's thread has entered the stall, so the close and Drop tests meet a peer proven silent; the two 100 ms sleeps that stood in for that proof are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b500efdfc6
commit
1e309f0270
1 changed files with 15 additions and 9 deletions
|
|
@ -31,6 +31,8 @@ enum PeerCommand {
|
|||
/// What the peer's thread says about itself, so a test waits for a fact and not for a sleep.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum PeerEvent {
|
||||
/// `Stall` has taken effect: the peer reads nothing from now on.
|
||||
Stalled,
|
||||
/// `Refuse` has taken effect: no Connect sent from now on is answered.
|
||||
Refusing,
|
||||
/// A Connect arrived while refusing.
|
||||
|
|
@ -66,8 +68,11 @@ impl Peer {
|
|||
self.commands.send(PeerCommand::Send(payload)).unwrap();
|
||||
}
|
||||
|
||||
/// Returns once the peer's thread has entered the stall, so what the test does next meets a peer that is
|
||||
/// silent, not one that has not yet read the command.
|
||||
fn stall(&self) {
|
||||
self.commands.send(PeerCommand::Stall).unwrap();
|
||||
self.expect(PeerEvent::Stalled);
|
||||
}
|
||||
|
||||
fn expect(&self, expected: PeerEvent) {
|
||||
|
|
@ -180,13 +185,16 @@ fn serve(
|
|||
session.disconnect(b"scripted-goodbye".to_vec()).unwrap();
|
||||
continue 'sessions;
|
||||
}
|
||||
PeerCommand::Stall => loop {
|
||||
match commands.recv() {
|
||||
Ok(PeerCommand::Disconnect) => continue 'sessions,
|
||||
Ok(PeerCommand::Stop) | Err(_) => return,
|
||||
Ok(_) => {}
|
||||
PeerCommand::Stall => {
|
||||
let _ = events.send(PeerEvent::Stalled);
|
||||
loop {
|
||||
match commands.recv() {
|
||||
Ok(PeerCommand::Disconnect) => continue 'sessions,
|
||||
Ok(PeerCommand::Stop) | Err(_) => return,
|
||||
Ok(_) => {}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
PeerCommand::Refuse => {}
|
||||
PeerCommand::Stop => return,
|
||||
}
|
||||
|
|
@ -1168,8 +1176,7 @@ fn close_waits_for_the_acknowledgement_and_says_when_it_does_not_come() {
|
|||
let client = CultMeshRudpSubscriptionClient::connect(options(&peer)).unwrap();
|
||||
client.subscribe("sub-1", vector_selection()).unwrap();
|
||||
peer.subscribe_id();
|
||||
peer.stall(); // reads nothing, acknowledges nothing
|
||||
thread::sleep(Duration::from_millis(100)); // the peer thread has taken the stall before the client closes
|
||||
peer.stall(); // returns once the peer reads nothing and acknowledges nothing
|
||||
let started = Instant::now();
|
||||
assert!(!client.close(), "no acknowledgement came");
|
||||
let waited = started.elapsed();
|
||||
|
|
@ -1184,7 +1191,6 @@ fn drop_does_not_wait_for_a_peer_that_acknowledges_nothing() {
|
|||
client.subscribe("sub-1", vector_selection()).unwrap();
|
||||
peer.subscribe_id();
|
||||
peer.stall();
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
let pump = client.pump_liveness();
|
||||
let started = Instant::now();
|
||||
drop(client);
|
||||
|
|
|
|||
Loading…
Reference in a new issue