Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make `test_terminal_eof` less flaky and faster (#39281)
Kirill Bulatov77cc55656ebe
diff --git a/crates/gpui/src/util.rs b/crates/gpui/src/util.rsindex adff4cdea82..badb6800821 100644--- a/crates/gpui/src/util.rs+++ b/crates/gpui/src/util.rs@@ -115,6 +115,7 @@ impl<T: Future> Future for WithTimeout<T> {#[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<F, T>(timeout: Duration, f: F) -> Result<T, ()>whereF: Future<Output = T>,diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rsindex f771012d028..7a8f4f89ee0 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));}}