diff options
author | olaola <olaola@google.com> | 2018-02-20 09:11:01 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-20 09:13:46 -0800 |
commit | 1001141f0674ff4b611814edcb00a5183680ef4a (patch) | |
tree | 4fd6392052b2a61377eb2502533e51b2dd1fd04d /tools/test | |
parent | fb915e8b7bd139e9c07e9354c43ab549e94cbc7a (diff) |
Roll forward of https://github.com/bazelbuild/bazel/commit/3904ac33a983fd8faebba1b52bcac5a3ff942029 (https://github.com/bazelbuild/bazel/commit/3904ac33a983fd8faebba1b52bcac5a3ff942029). Fix #4625 by running the test process in a sub-shell.
Apparently, nested background processes interfere with SIGINT handling in bash. I don't 100% understand why and how, but I do have a small bash script that demonstrates the problem: script A that spawns a background process, sends it a SIGINT, and verifies it was received. The script works, *unless* run in the background by a process B; this extra layer of backgrounding cause process A's logic to stop working. See experimental/users/olaola/shell/ for examples. See also https://stackoverflow.com/questions/48847722/nested-background-processes-and-sigint-handling
*** Original change description ***
Fixing test-setup.sh occasionally missing stdout/stderr, on systems where "tail --pid" is supported.
The solutions aren't mine, the new test was taken from Ola's unknown commit and the way to avoid race condition courtesy of sethkoehler@
Mitigates #4608 for compatible Linux systems.
TESTED=presubmits, manual shell tests on new bazel
RELNOTES: None
PiperOrigin-RevId: 186312008
Diffstat (limited to 'tools/test')
-rwxr-xr-x | tools/test/test-setup.sh | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index aa6f7223b8..002edb8bdf 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -218,10 +218,30 @@ for signal in $signals; do done start=$(date +%s) -if [ -z "$COVERAGE_DIR" ]; then - "${TEST_PATH}" "$@" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? +# Check if we have tail --pid option +dummy=1 & +pid=$! +has_tail=true +tail -fq --pid $pid -s 0.001 /dev/null &> /dev/null || has_tail=false + +if [ "$has_tail" == true ] && [ -z "$no_echo" ]; then + touch "${XML_OUTPUT_FILE}.log" + if [ -z "$COVERAGE_DIR" ]; then + ("${TEST_PATH}" "$@" &>"${XML_OUTPUT_FILE}.log") & + pid=$! + else + ("$1" "$TEST_PATH" "${@:3}" &> "${XML_OUTPUT_FILE}.log") & + pid=$! + fi + tail -fq --pid $pid -s 0.001 "${XML_OUTPUT_FILE}.log" + wait $pid + exitCode=$? else - "$1" "$TEST_PATH" "${@:3}" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? + if [ -z "$COVERAGE_DIR" ]; then + "${TEST_PATH}" "$@" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? + else + "$1" "$TEST_PATH" "${@:3}" 2> >(tee -a "${XML_OUTPUT_FILE}.log" >&2) 1> >(tee -a "${XML_OUTPUT_FILE}.log") 2>&1 || exitCode=$? + fi fi for signal in $signals; do |