Skip to content

fix: use PIPESTATUS to capture correct exit code in collect() - #9

Closed
mobs75 wants to merge 1 commit into
apache:mainfrom
mobs75:fix/collect-exit-code-pipestatus-clean
Closed

fix: use PIPESTATUS to capture correct exit code in collect()#9
mobs75 wants to merge 1 commit into
apache:mainfrom
mobs75:fix/collect-exit-code-pipestatus-clean

Conversation

@mobs75

Copy link
Copy Markdown

The collect() function in tests/all.sh used:

if"$@"2>&1| tee _log

This captures the exit status of tee (always 0) instead of the tested script's own exit code, because bash pipelines report $? from the last command in the pipe.

As a result, every test script that fails with a non-zero exit code was still recorded as SUCCESS in _results and in the final summary.

Confirmed on a kind cluster: after this fix, 5-sys-seaweedfs.sh and 11-sso-mock.sh, which fail with a real error, are now correctly reported as FAIL instead of SUCCESS. The overall task test run now also exits non-zero when a test genuinely fails, instead of always reporting success.

Fix: check ${PIPESTATUS[0]} (the exit code of the first command in the pipeline) instead of the pipeline's own exit status.

The collect() function used 'if "$@" 2>&1 | tee _log', which captures
the exit status of 'tee' (always 0) instead of the tested script, due
to how bash pipelines report $?. This caused every failing test to be
recorded as SUCCESS in the final summary, regardless of its actual
exit code.
Confirmed with 11-sys-spark.sh: the script exits 1 explicitly after
'FAIL: Spark master not ready', but was still reported as
'SUCCESS ./11-sys-spark.sh' in the summary before this fix.
Fixed by checking ${PIPESTATUS[0]} instead of the pipeline's own
exit code.
@d4rkstar

Copy link
Copy Markdown
Contributor

Hello @mobs75 : please open this on 0.9.1 branch please

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mobs75@d4rkstar