diff --git a/crates/gpui/src/util.rs b/crates/gpui/src/util.rs index adff4cdea8..badb680082 100644 --- a/crates/gpui/src/util.rs +++ b/crates/gpui/src/util.rs @@ -115,6 +115,7 @@ impl Future for WithTimeout { #[cfg(any(test, feature = "test-support"))] /// Uses smol executor to run a given future no longer than the timeout specified. +/// Note that this won't "rewind" on `cx.executor().advance_clock` call, truly waiting for the timeout to elapse. pub async fn smol_timeout(timeout: Duration, f: F) -> Result where F: Future, diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index f771012d02..7a8f4f89ee 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -2308,8 +2308,9 @@ mod tests { }) .detach(); + let first_event = Event::Wakeup; let wakeup = event_rx.recv().await.expect("No wakeup event received"); - assert_eq!(wakeup, Event::Wakeup, "Expected wakeup, got {wakeup:?}"); + assert_eq!(wakeup, first_event, "Expected wakeup, got {wakeup:?}"); terminal.update(cx, |terminal, _| { let success = terminal.try_keystroke(&Keystroke::parse("ctrl-c").unwrap(), false); @@ -2320,13 +2321,13 @@ mod tests { assert!(success, "Should have registered ctrl-d sequence"); }); - let mut all_events = vec![Event::Wakeup]; - while let Ok(Ok(new_event)) = - smol_timeout(Duration::from_millis(500), event_rx.recv()).await - { + let mut all_events = vec![first_event]; + while let Ok(Ok(new_event)) = smol_timeout(Duration::from_secs(1), event_rx.recv()).await { all_events.push(new_event.clone()); + if new_event == Event::CloseTerminal { + break; + } } - assert!( all_events.contains(&Event::CloseTerminal), "EOF command sequence should have triggered a TTY terminal exit, but got events: {all_events:?}", @@ -2375,6 +2376,10 @@ mod tests { { let exit_status = completion_rx.recv().await.ok().flatten(); if let Some(exit_status) = exit_status { + assert!( + !exit_status.success(), + "Wrong shell command should result in a failure" + ); assert_eq!(exit_status.code(), Some(1)); } }