From 2a82822500b0c0639251cebd931d07ca99442a88 Mon Sep 17 00:00:00 2001 From: Jake Wallin Date: Mon, 19 Oct 2026 19:33:49 +0000 Subject: [PATCH] tests/tail: wait for follow-mode output Reuse bounded output polling for the truncation and symlink-append follow tests. Fixed delays can stop tail before it emits the final line on slow macOS CI. Validation: the three affected tests and Clippy pass. The truncation and symlink cases also pass with a 2.2-second startup delay and a forced 1.5-second polling interval. Refs #12335. --- tests/by-util/test_tail.rs | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index d434874e7e0..7c50341be2c 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -2299,28 +2299,28 @@ fn test_follow_name_truncate1() { .stdout_is(expected_stdout); } +fn wait_for_output( + child: &mut uutests::util::UChild, + expected_stdout: &str, + expected_stderr: &str, +) { + for _ in 0..500 { + if child.stdout_all() == expected_stdout && child.stderr_all() == expected_stderr { + return; + } + child.delay(10); + } + child + .make_assertion() + .with_all_output() + .stdout_is(expected_stdout) + .stderr_is(expected_stderr); +} + #[test] #[cfg(all(not(target_os = "android"), not(target_os = "freebsd")))] // FIXME: for currently not working platforms #[cfg_attr(wasi_runner, ignore = "WASI: tail follow mode disabled")] fn test_follow_name_truncate2() { - fn wait_for_output( - child: &mut uutests::util::UChild, - expected_stdout: &str, - expected_stderr: &str, - ) { - for _ in 0..500 { - if child.stdout_all() == expected_stdout && child.stderr_all() == expected_stderr { - return; - } - child.delay(10); - } - child - .make_assertion() - .with_all_output() - .stdout_is(expected_stdout) - .stderr_is(expected_stderr); - } - // This test triggers a truncate event while `tail --follow=name file` is running. // $ ((sleep 1 && echo -n "x\nx\nx\n" >> file && sleep 1 && \ // echo -n "x\n" > file &)>/dev/null 2>&1 &) ; tail --follow=name file @@ -2383,7 +2383,7 @@ fn test_follow_name_truncate3() { p.make_assertion_with_delay(delay).is_alive(); at.truncate(source, "x\n"); - p.delay(delay); + wait_for_output(&mut p, expected_stdout, ""); p.make_assertion().is_alive(); p.kill() @@ -5475,11 +5475,11 @@ fn test_follow_symlink_appends() { let mut p = ucmd .args(&["-s.1", "--max-unchanged-stats=1", follow, "latest.log"]) .run_no_wait(); - p.delay(500); + wait_for_output(&mut p, "a\n", ""); at.append("2026-09-01.log", "b\n"); - p.delay(500); + wait_for_output(&mut p, "a\nb\n", ""); at.append("2026-09-01.log", "c\n"); - p.delay(500); + wait_for_output(&mut p, "a\nb\nc\n", ""); p.kill() .make_assertion() .with_all_output()