From 4bfb4623873e4b74155304689b40e6a4c2842676 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Sun, 24 Oct 2021 22:15:14 +0200 Subject: [PATCH] test_tail: add test_retry5 --- tests/by-util/test_tail.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 980a755ba..4f12acf65 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -645,6 +645,40 @@ fn test_retry4() { } } +#[test] +#[cfg(target_os = "linux")] // FIXME: fix this test for BSD/macOS +fn test_retry5() { + // gnu/tests/tail-2/retry.sh + // Ensure that `tail --follow=descriptor --retry` exits when the file appears untailable. + + 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 been replaced with an untailable file; giving up on this name\n\ + tail: no files remaining\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.mkdir(missing); + sleep(Duration::from_millis(delay)); + + p.kill().unwrap(); + + let (buf_stdout, buf_stderr) = take_stdout_stderr(&mut p); + assert!(buf_stdout.is_empty()); + assert_eq!(buf_stderr, expected_stderr); + + at.rmdir(missing); + args.pop(); + } +} + // gnu/tests/tail-2/descriptor-vs-rename.sh let ts = TestScenario::new(util_name!()); let at = &ts.fixtures;