tests: avoid false failure in tail inotify test
[coreutils.git] / tests / tail-2 / F-vs-rename.sh
blob760bbc23cc87dd715da8c7fe4910e802d3a8c43a
1 #!/bin/sh
2 # Demonstrate that tail -F works when renaming the tailed files.
3 # Between coreutils 7.5 and 8.2 inclusive, 'tail -F a b' would
4 # stop tracking additions to b after 'mv a b'.
6 # Copyright (C) 2009-2016 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
22 print_ver_ tail
24 check_tail_output()
26 local delay="$1"
27 grep "$tail_re" out ||
28 { sleep $delay; return 1; }
31 # Terminate any background tail process
32 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
34 # Speedup the non inotify case
35 fastpoll='-s.1 --max-unchanged-stats=1'
37 for mode in '' '---disable-inotify'; do
38 rm -f a b out
39 touch a b || framework_failure_
41 tail $mode -F $fastpoll a b > out 2>&1 & pid=$!
43 # Wait up to 12.7s for tail to start.
44 echo x > a
45 tail_re='^x$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; }
47 mv a b || framework_failure_
49 # Wait 12.7s for this diagnostic:
50 # tail: 'a' has become inaccessible: No such file or directory
51 tail_re='inaccessible' retry_delay_ check_tail_output .1 7 ||
52 { cat out; fail=1; }
54 echo x > a
55 # Wait up to 12.7s for this to appear in the output:
56 # "tail: '...' has appeared; following new file"
57 tail_re='has appeared' retry_delay_ check_tail_output .1 7 ||
58 { echo "$0: a: unexpected delay?"; cat out; fail=1; }
60 echo y >> b
61 # Wait up to 12.7s for "y" to appear in the output:
62 tail_f_vs_rename_2() {
63 local delay="$1"
64 tr '\n' @ < out | grep '@@==> b <==@y@$' > /dev/null ||
65 { sleep $delay; return 1; }
67 retry_delay_ tail_f_vs_rename_2 .1 7 ||
68 { echo "$0: b: unexpected delay?"; cat out; fail=1; }
70 echo z >> a
71 # Wait up to 12.7s for "z" to appear in the output:
72 tail_f_vs_rename_3() {
73 local delay="$1"
74 tr '\n' @ < out | grep '@@==> a <==@z@$' > /dev/null ||
75 { sleep $delay; return 1; }
77 retry_delay_ tail_f_vs_rename_3 .1 7 ||
78 { echo "$0: a: unexpected delay?"; cat out; fail=1; }
80 cleanup_
81 done
83 Exit $fail