Make test_terminal_eof less flaky and faster (#39281)
Release Notes: - N/A
This commit is contained in:
@@ -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, ()>
|
||||
where
|
||||
F: Future<Output = T>,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user