diff options
author | Martin Schwenke <martin@meltin.net> | 2019-03-28 14:26:52 +1100 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2019-05-17 07:18:29 +0000 |
commit | b594f5161dd8845d19f7d12a300751bd4d040eba (patch) | |
tree | 71effeac87e2936c7e25f0e0c850b0b4f82110f2 /ctdb | |
parent | 7c97bc83284e09ac028a0a7ce04b039b97eae0c7 (diff) | |
download | samba-b594f5161dd8845d19f7d12a300751bd4d040eba.tar.gz |
ctdb-tests: Make try_command_on_node less error-prone
This sometimes fails, apparently due to a cat process in onnode
getting EAGAIN. The conclusion is that tests that process large
amounts of output should not depend on a sub-shell delivering that
output into a shell variable.
Change try_command_on_node() to leave all of the output in file
$outfile and just put the first 1KB into $out. $outfile is removed
after each test completes.
Change the implementation of sanity_check_output() to use $outfile
instead of $out.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13924
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 9d02452a24625df5f62fd6d45a16effe2fa45fbe)
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/tests/scripts/integration.bash | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash index bc4d2b429ff..9185b1fb8e3 100644 --- a/ctdb/tests/scripts/integration.bash +++ b/ctdb/tests/scripts/integration.bash @@ -77,7 +77,20 @@ ctdb_test_init () ######################################## -# Sets: $out +# Sets: $out, $outfile +# * The first 1KB of output is put into $out +# * Tests should use $outfile for handling large output +# * $outfile is removed after each test +out="" +outfile="${TEST_VAR_DIR}/try_command_on_node.out" + +outfile_cleanup () +{ + rm -f "$outfile" +} + +ctdb_test_exit_hook_add outfile_cleanup + try_command_on_node () { local nodespec="$1" ; shift @@ -96,17 +109,18 @@ try_command_on_node () local cmd="$*" - out=$(onnode -q $onnode_opts "$nodespec" "$cmd" 2>&1) || { - + if ! onnode -q $onnode_opts "$nodespec" "$cmd" >"$outfile" 2>&1 ; then echo "Failed to execute \"$cmd\" on node(s) \"$nodespec\"" - echo "$out" + cat "$outfile" return 1 - } + fi if $verbose ; then echo "Output of \"$cmd\":" - echo "$out" + cat "$outfile" fi + + out=$(dd if="$outfile" bs=1k count=1 2>/dev/null) } sanity_check_output () @@ -116,7 +130,7 @@ sanity_check_output () local ret=0 - local num_lines=$(echo "$out" | wc -l) + local num_lines=$(wc -l <"$outfile") echo "There are $num_lines lines of output" if [ $num_lines -lt $min_lines ] ; then echo "BAD: that's less than the required number (${min_lines})" @@ -125,7 +139,7 @@ sanity_check_output () local status=0 local unexpected # local doesn't pass through status of command on RHS. - unexpected=$(echo "$out" | egrep -v "$regexp") || status=$? + unexpected=$(grep -Ev "$regexp" "$outfile") || status=$? # Note that this is reversed. if [ $status -eq 0 ] ; then |