test: fix flaky tests and increase frame stability timeout

This commit is contained in:
alexandre pasmantier 2025-07-13 12:26:48 +02:00
parent da9484a491
commit 23f38f9bb4
5 changed files with 22 additions and 12 deletions

View File

@ -17,7 +17,7 @@ fn test_watch_reloads_source_command() {
// This monitors the temp directory and updates every 0.5 seconds
let cmd = tv_local_config_and_cable_with_args(&[
"--watch",
"1",
"0.5",
"--source-command",
"ls",
tmp_dir.to_str().unwrap(),
@ -48,7 +48,7 @@ fn test_tick_rate_valid_value_starts_application() {
// Start Television with a custom tick rate
let cmd =
tv_local_config_and_cable_with_args(&["files", "--tick-rate", "30"]);
tv_local_config_and_cable_with_args(&["files", "--tick-rate", "50"]);
let mut child = tester.spawn_command_tui(cmd);
// Verify the TUI launched successfully

View File

@ -106,14 +106,16 @@ fn test_preview_offset_with_preview_command() {
let cmd = tv_local_config_and_cable_with_args(&[
"files",
"--input",
"CHANGELOG.md",
"CODE_OF_CONDUCT.md",
"-p",
"cat -n {}",
"--preview-offset",
"500",
"50",
]);
let mut child = tester.spawn_command_tui(cmd);
// Verify the preview panel is active
tester.assert_tui_frame_contains("││ 500 ");
tester.assert_tui_frame_contains("││ 50");
// Send Ctrl+C to exit
tester.send(&ctrl('c'));

View File

@ -105,7 +105,7 @@ fn test_scroll_preview_keybindings() {
let cmd = tv_local_config_and_cable_with_args(&[
"files",
"--input",
"CHANGELOG.md",
"README.md",
]);
let mut child = tester.spawn_command_tui(cmd);

View File

@ -212,7 +212,7 @@ impl PtyTester {
}
/// How long to wait for the TUI to stabilize before asserting its output.
const FRAME_STABILITY_TIMEOUT: Duration = Duration::from_millis(1000);
const FRAME_STABILITY_TIMEOUT: Duration = Duration::from_millis(5000);
/// Gets the current TUI frame, ensuring it has stabilized.
///
@ -247,12 +247,16 @@ impl PtyTester {
// wait for the UI to stabilize with a timeout
let mut frame = String::new();
let start_time = std::time::Instant::now();
loop {
// wait till we get 3 consecutive frames that are the same
let mut counter = 0;
while counter < 3 {
let new_frame = self.read_tui_output();
if new_frame == frame {
break;
counter += 1;
} else {
frame = new_frame;
counter = 0;
}
frame = new_frame;
assert!(
start_time.elapsed() < Self::FRAME_STABILITY_TIMEOUT,
"UI did not stabilize within {:?}. Last frame:\n{}",
@ -260,7 +264,7 @@ impl PtyTester {
frame
);
// Sleep briefly to allow the UI to update
sleep(DEFAULT_DELAY / 6);
sleep(Duration::from_millis(50));
}
frame
}

View File

@ -7,7 +7,11 @@ use common::*;
fn toggle_preview() {
let mut tester = PtyTester::new();
let mut child =
tester.spawn_command_tui(tv_local_config_and_cable_with_args(&[]));
tester.spawn_command_tui(tv_local_config_and_cable_with_args(&[
"files",
"-p",
"cat -n {}",
]));
let with_preview =
"╭───────────────────────── files ──────────────────────────╮";