From 77cc55656ebef14fb43a68e573bd9b62a29c2042 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 1 Oct 2025 15:14:06 +0300 Subject: [PATCH] Make `test_terminal_eof` less flaky and faster (#39281) Release Notes: - N/A --- crates/gpui/src/util.rs | 1 + crates/terminal/src/terminal.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/util.rs b/crates/gpui/src/util.rs index adff4cdea824660780b7c7fb4e3b6a10d2f72b7b..badb68008216400464e997f3252e9467edb234c6 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 f771012d028ef484e6b0f6eb25c503088e07af8d..7a8f4f89ee0e8f06d19a4c643a0a960bbe622399 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)); } }