diff --git a/src/client.rs b/src/client.rs index a69ceca..0426344 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2077,7 +2077,12 @@ mod remote_tests { // As the real client: a relay that fails at once may close the pipe before Hello. let _ = hello().write_to(&mut stdin); let mut screen = Vec::new(); - let seen = pump(Vec::new(), stdout, &mut screen, false, |_| {}); + // The `lost` fake cuts the link only once the client has the marker. + let seen = pump(Vec::new(), stdout, &mut screen, false, |r| { + if r.armed { + let _ = std::fs::write(self.dir.join("armed"), ""); + } + }); drop(stdin); let (exit, said) = finish(child, stderr); (seen, screen, exit, said) @@ -2273,8 +2278,14 @@ mod remote_tests { #[test] fn a_link_that_dies_after_the_arming_is_a_loss() { let fake = Fake::new("lost", "lost"); - let server = fake.serve(|s| { + let armed = fake.dir.join("armed"); + let server = fake.serve(move |s| { s.write_all(ARMED).unwrap(); + // Open until the client has the marker, however slow the machine, then long enough for the fake ssh to cut the link. + let t = std::time::Instant::now(); + while !armed.exists() && t.elapsed() < Duration::from_secs(60) { + std::thread::sleep(Duration::from_millis(20)); + } std::thread::sleep(Duration::from_secs(3)); }); let (seen, _, exit, said) = fake.run("1"); diff --git a/tests/fixtures/fake-ssh b/tests/fixtures/fake-ssh index 9b4831c..24975c1 100755 --- a/tests/fixtures/fake-ssh +++ b/tests/fixtures/fake-ssh @@ -21,11 +21,11 @@ case $last in unset NERD_SOCKET NERD_INSTANCE export NERD_STATE_DIR="$dir/state" HOME="$dir" if [ "$mode" = lost ]; then - # The link drops a second in: the relay dies with no word, ssh exits 255. + # The link drops once the client has the armed marker: the relay dies with no word, ssh exits 255. "$dir/nerd" --relay "$id" <&0 & pid=$! - sleep 1 - kill -9 $pid + while [ ! -e "$dir/armed" ] && kill -0 $pid 2>/dev/null; do sleep 0.05; done + kill -9 $pid 2>/dev/null : > "$dir/ended" exit 255 fi