Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions tests/by-util/test_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,25 @@ fn test_follow_name_remove(
.stderr_is(follow_name_gone_stderr(&ts.util_name, file, retry));
}

/// Polls a running tail until its output matches, for up to 5 s, then asserts it.
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);
}

#[uutests::wasi_ignore(TailFollowDisabled)]
#[test]
#[cfg(all(not(target_os = "android"), not(target_os = "freebsd")))] // FIXME: for currently not working platforms
Expand Down Expand Up @@ -2501,12 +2520,7 @@ fn test_follow_name_truncate1() {
// appears the truncate/restore below are guaranteed to be observed as events.
// A fixed delay isn't enough here: a slow-starting child process (observed on
// macOS CI, see #12335) can otherwise race ahead of tail's own startup.
for _ in 0..500 {
if p.stdout_all() == initial_stdout {
break;
}
p.delay(10);
}
wait_for_output(&mut p, initial_stdout, "");

at.copy(source, backup);
p.delay(delay);
Expand All @@ -2532,24 +2546,6 @@ fn test_follow_name_truncate1() {
#[test]
#[cfg(all(not(target_os = "android"), not(target_os = "freebsd")))] // FIXME: for currently not working platforms
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
Expand Down Expand Up @@ -6080,19 +6076,20 @@ fn test_follow_symlink_appends() {
// Appends to the target of a symlink reach tail through the link, by
// descriptor and by name alike: under --follow=name a symlink given on
// the command line is not a file that was replaced by a symlink.
// Wait for output, not a fixed delay: on macOS tail can take over a second to start.
// It watches the file before its first read, so later appends must arrive via the watch.
for follow in ["-f", "-F"] {
let (at, mut ucmd) = at_and_ucmd!();
at.write("2026-09-01.log", "a\n");
at.symlink_file("2026-09-01.log", "latest.log");
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");
// macOS reports changes late (FSEvents), so wait the platform default
p.delay(DEFAULT_SLEEP_INTERVAL_MILLIS);
wait_for_output(&mut p, "a\nb\n", "");
at.append("2026-09-01.log", "c\n");
p.delay(DEFAULT_SLEEP_INTERVAL_MILLIS);
wait_for_output(&mut p, "a\nb\nc\n", "");
p.kill()
.make_assertion()
.with_all_output()
Expand Down
Loading