[test] presubmit: re-run verbosely on failure
This will help get better logs for failures observed in infra.
Also if the retry passes, print an additional message about test
flakiness.
Bug: 390427892
Change-Id: I9da693b91097c66ed49c356c0506f76e94492263
Reviewed-on: https://fuchsia-review.googlesource.com/c/rsclient/+/1383451
Reviewed-by: Aaron Wood <aaronwood@google.com>
Commit-Queue: David Fang <fangism@google.com>
diff --git a/scripts/infra/presubmit.sh b/scripts/infra/presubmit.sh
index 547e459..bab980a 100755
--- a/scripts/infra/presubmit.sh
+++ b/scripts/infra/presubmit.sh
@@ -65,7 +65,18 @@
readonly CIPD_YAML_PATH="bazel-bin/cipd.yaml"
# Test
-run_bazel test --test_timeout=10 --test_output=errors "${universe[@]}"
+# On failure, re-run with streamed output for better visibility.
+run_bazel test --test_timeout=10 --test_output=errors "${universe[@]}" || {
+ original_status="$?"
+ echo "=== Tests failed. Re-running with streamed output... ==="
+ run_bazel test --test_timeout=10 --test_output=streamed "${universe[@]}"
+ rerun_status="$?"
+ [[ "$rerun_status" == "$original_status" ]] || {
+ echo "Inconsistent test exit codes $original_status vs. $rerun_status. *** There could be test flakes. ***"
+ }
+ # Force it to fail, even if re-run passes, to help catch flakes.
+ exit "$original_status"
+}
# Install
# Unpack the tarball for packaging and local testing.