summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-04-08 13:43:35 +0100
committerAlexander Larsson <alexander.larsson@gmail.com>2021-04-12 11:07:10 +0200
commite9c217adc1de2102c6d4412225827affb429e084 (patch)
tree62820b5e6dd42eb4ac45c79b270c0d266eec5a9d
parent3ebf371fc281da37c2814bfd7f9d899156eff660 (diff)
downloadflatpak-e9c217adc1de2102c6d4412225827affb429e084.tar.gz
test-basic: Don't fail if head -2 exits before flatpak does
The output might be written to the pipe by `flatpak --help` and/or read from the pipe by `head -2` in more than one batch. If `head -2` reads the first two lines before `flatpak --help` has written everything, it will exit, causing the pipe to have no process at the read end. This results in `flatpak --help` being killed by `SIGPIPE` next time it tries to write to the pipe, because it has not opted out of this behaviour (as shell tools usually shouldn't). We're running under `set -o pipefail`, so this causes a nonzero exit status that makes the test fail. Worse, this failure is intermittent, because `head -2` *usually* doesn't exit until `flatpak --help` has already written out everything it is going to write - it depends on the precise behaviour of read(), write() and kernel scheduling. We know that `flatpak --help` output is not *that* long, so it's OK for `flatpak --help` not to be terminated early: we can send it all into an intermediate file, and then run `head` on the file. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rwxr-xr-xtests/test-basic.sh7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/test-basic.sh b/tests/test-basic.sh
index 24943934..76369b35 100755
--- a/tests/test-basic.sh
+++ b/tests/test-basic.sh
@@ -73,10 +73,11 @@ for cmd in install update uninstall list info config repair create-usb \
build-sign build-update-repo build-commit-from repo kill history \
mask;
do
- ${FLATPAK} $cmd --help | head -2 > help_out
+ ${FLATPAK} $cmd --help > help_out
+ head -2 help_out > help_out2
- assert_file_has_content help_out "^Usage:$"
- assert_file_has_content help_out "flatpak $cmd"
+ assert_file_has_content help_out2 "^Usage:$"
+ assert_file_has_content help_out2 "flatpak $cmd"
done
ok "command help"