From 5770921f522f017fd8ed6edb35a44ec17f1c3c46 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Sun, 24 Oct 2021 22:13:58 +0200 Subject: [PATCH] test_tail: add test_retry4 --- tests/by-util/test_tail.rs | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 800cd7662..980a755ba 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -605,6 +605,46 @@ fn test_retry3() { } } +#[test] +#[cfg(target_os = "linux")] // FIXME: fix this test for BSD/macOS +fn test_retry4() { + // gnu/tests/tail-2/retry.sh + // Ensure that `tail --retry --follow=descriptor` waits for the file to appear. + // Ensure truncation is detected. + + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + let missing = "missing"; + + let expected_stderr = "tail: warning: --retry only effective for the initial open\n\ + tail: cannot open 'missing' for reading: No such file or directory\n\ + tail: 'missing' has appeared; following new file\n\ + tail: missing: file truncated\n"; + let expected_stdout = "X1\nX\n"; + let delay = 1000; + let mut args = vec!["--follow=descriptor", "--retry", missing, "--use-polling"]; + for _ in 0..2 { + let mut p = ts.ucmd().args(&args).run_no_wait(); + + sleep(Duration::from_millis(delay)); + at.touch(missing); + sleep(Duration::from_millis(delay)); + at.truncate(missing, "X1\n"); + sleep(Duration::from_millis(3 * delay)); + at.truncate(missing, "X\n"); + sleep(Duration::from_millis(3 * delay)); + + p.kill().unwrap(); + + let (buf_stdout, buf_stderr) = take_stdout_stderr(&mut p); + assert_eq!(buf_stdout, expected_stdout); + assert_eq!(buf_stderr, expected_stderr); + + at.remove(missing); + args.pop(); + } +} + // gnu/tests/tail-2/descriptor-vs-rename.sh let ts = TestScenario::new(util_name!()); let at = &ts.fixtures;