From 23f38f9bb43cb5b0f3f271801014e1992e4aead6 Mon Sep 17 00:00:00 2001 From: alexandre pasmantier Date: Sun, 13 Jul 2025 12:26:48 +0200 Subject: [PATCH] test: fix flaky tests and increase frame stability timeout --- tests/cli/cli_monitoring.rs | 4 ++-- tests/cli/cli_preview.rs | 8 +++++--- tests/cli/cli_ui_behavior.rs | 2 +- tests/common/mod.rs | 14 +++++++++----- tests/ui.rs | 6 +++++- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/cli/cli_monitoring.rs b/tests/cli/cli_monitoring.rs index 218c4bf..f6460b8 100644 --- a/tests/cli/cli_monitoring.rs +++ b/tests/cli/cli_monitoring.rs @@ -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 diff --git a/tests/cli/cli_preview.rs b/tests/cli/cli_preview.rs index da848e8..c5d776c 100644 --- a/tests/cli/cli_preview.rs +++ b/tests/cli/cli_preview.rs @@ -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')); diff --git a/tests/cli/cli_ui_behavior.rs b/tests/cli/cli_ui_behavior.rs index 3779671..19ef6e9 100644 --- a/tests/cli/cli_ui_behavior.rs +++ b/tests/cli/cli_ui_behavior.rs @@ -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); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 738b8a2..645cf42 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -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 } diff --git a/tests/ui.rs b/tests/ui.rs index c44f999..81ae36e 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -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 ──────────────────────────╮";