aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell/testenv.sh
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-07-02 00:11:40 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-02 00:13:02 -0700
commita5e2f1b3d0679ef82d658a7e02bffa8d515faf8d (patch)
treec7c3889b719f72a02f48fdf9926fb4b2275b4c2c /src/test/shell/testenv.sh
parent4f64b77a3dd8e4ccdc8077051927985f9578a3a5 (diff)
Windows,tests: port rule_test_test
Port //src/test/shell/bazel:rule_test_test to Windows: - Use the Bash runfiles library (in @bazel_tools) - Update testenv.sh to retry failed "rm" commands because often they attempt to delete a Bazel's output directory that is still in the middle of shutting down, and just needs a bit of time to finish doing so. See https://github.com/bazelbuild/bazel/issues/4292 Change-Id: I6a7687d15ae3af2ca605149fa75ff48bf2fb89c8 Closes #5490. Change-Id: I6a7687d15ae3af2ca605149fa75ff48bf2fb89c8 PiperOrigin-RevId: 202903547
Diffstat (limited to 'src/test/shell/testenv.sh')
-rwxr-xr-xsrc/test/shell/testenv.sh44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index c1a9099819..b2f6e24147 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -256,6 +256,25 @@ log_info "bazel binary is at $PATH_TO_BAZEL_WRAPPER"
# Here we unset variable that were set by the invoking Blaze instance
unset JAVA_RUNFILES
+# Runs a command, retrying if needed for a fixed timeout.
+#
+# Necessary to use it on Windows, typically when deleting directory trees,
+# because the OS cannot delete open files, which we attempt to do when deleting
+# workspaces where a Bazel server is still in the middle of shutting down.
+# (Because "bazel shutdown" returns sooner than the server actually shuts down.)
+function try_with_timeout() {
+ for i in {1..120}; do
+ if $* ; then
+ break
+ fi
+ if (( i == 10 )) || (( i == 30 )) || (( i == 60 )) ; then
+ log_info "try_with_timeout($*): no success after $i seconds" \
+ "(timeout in $((120-i)) seconds)"
+ fi
+ sleep 1
+ done
+}
+
function setup_bazelrc() {
cat >$TEST_TMPDIR/bazelrc <<EOF
# Set the user root properly for this test invocation.
@@ -355,7 +374,7 @@ workspaces=()
# Set-up a new, clean workspace with only the tools installed.
function create_new_workspace() {
new_workspace_dir=${1:-$(mktemp -d ${TEST_TMPDIR}/workspace.XXXXXXXX)}
- rm -fr ${new_workspace_dir}
+ try_with_timeout rm -fr ${new_workspace_dir}
mkdir -p ${new_workspace_dir}
workspaces+=(${new_workspace_dir})
cd ${new_workspace_dir}
@@ -374,7 +393,7 @@ function create_new_workspace() {
function setup_clean_workspace() {
export WORKSPACE_DIR=${TEST_TMPDIR}/workspace
log_info "setting up client in ${WORKSPACE_DIR}" >> $TEST_log
- rm -fr ${WORKSPACE_DIR}
+ try_with_timeout rm -fr ${WORKSPACE_DIR}
create_new_workspace ${WORKSPACE_DIR}
[ "${new_workspace_dir}" = "${WORKSPACE_DIR}" ] \
|| log_fatal "Failed to create workspace"
@@ -397,8 +416,8 @@ function setup_clean_workspace() {
# Shut down this server in case the tests will run Bazel in a different output
# root, otherwise we could not clean up $WORKSPACE_DIR (under $TEST_TMPDIR)
# once the test is finished.
- bazel shutdown
- rm -f "$bazel_stdout" "$bazel_stderr"
+ bazel shutdown >&/dev/null
+ try_with_timeout rm -f "$bazel_stdout" "$bazel_stderr"
if is_windows; then
export BAZEL_SH="$(cygpath --windows /bin/bash)"
@@ -413,18 +432,18 @@ function cleanup_workspace() {
cd ${WORKSPACE_DIR}
bazel clean >> $TEST_log 2>&1 # Clean up the output base
# Shut down this server to allow any cleanup code to delete its output_root.
- bazel shutdown
+ bazel shutdown >&/dev/null
for i in *; do
if ! is_tools_directory "$i"; then
- rm -fr "$i"
+ try_with_timeout rm -fr "$i"
fi
done
touch WORKSPACE
fi
for i in "${workspaces[@]}"; do
if [ "$i" != "${WORKSPACE_DIR:-}" ]; then
- rm -fr $i
+ try_with_timeout rm -fr $i
fi
done
workspaces=()
@@ -436,16 +455,7 @@ function cleanup() {
log_info "Cleaning up BAZEL_INSTALL_BASE under $BAZEL_INSTALL_BASE"
# Windows takes its time to shut down Bazel and we can't delete A-server.jar
# until then, so just give it time and keep trying for 2 minutes.
- for i in {1..120}; do
- if rm -fr "${BAZEL_INSTALL_BASE}" >&/dev/null ; then
- break
- fi
- if (( i == 10 )) || (( i == 30 )) || (( i == 60 )) ; then
- log_info "Test cleanup: couldn't delete ${BAZEL_INSTALL_BASE} after $i seconds" \
- "(Timeout in $((120-i)) seconds.)"
- fi
- sleep 1
- done
+ try_with_timeout rm -fr "${BAZEL_INSTALL_BASE}" >&/dev/null
fi
}