aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yue Gan <yueg@google.com>2016-09-13 11:51:16 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-09-13 12:32:14 +0000
commitef0f36956a016c553c506676373637c9c3d00ee9 (patch)
treeaec3891d5679087ad7c292a8e326c971cf51d129
parentd083c76ebca3b77a3a7c0b44ce47b003072f0499 (diff)
opensource bazel_testjobs.sh
-- MOS_MIGRATED_REVID=132985974
-rw-r--r--src/test/shell/integration/BUILD7
-rwxr-xr-xsrc/test/shell/integration/bazel_testjobs_test.sh100
2 files changed, 107 insertions, 0 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index 81824f8744..8e794ab575 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -69,6 +69,13 @@ sh_test(
)
sh_test(
+ name = "bazel_testjobs_test",
+ srcs = ["bazel_testjobs_test.sh"],
+ data = [":test-deps"],
+ shard_count = 3,
+)
+
+sh_test(
name = "bazel_query_test",
size = "medium",
srcs = ["bazel_query_test.sh"],
diff --git a/src/test/shell/integration/bazel_testjobs_test.sh b/src/test/shell/integration/bazel_testjobs_test.sh
new file mode 100755
index 0000000000..12aca46878
--- /dev/null
+++ b/src/test/shell/integration/bazel_testjobs_test.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+#
+# Copyright 2016 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Load test environment
+source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
+ || { echo "testenv.sh not found!" >&2; exit 1; }
+
+create_and_cd_client
+put_bazel_on_path
+EXTRA_BAZELRC="test --nocache_test_results"
+write_default_bazelrc
+
+# End of preamble.
+
+function create_test_files() {
+ # We use hardlinks to this file as a communication mechanism between
+ # test runs.
+ touch $TEST_TMPDIR/counter
+
+ mkdir dir
+
+ cat <<EOF > dir/test.sh
+#!/bin/sh
+# hard link
+z=$TEST_TMPDIR/\$(basename \$(mktemp -u))
+ln $TEST_TMPDIR/counter \${z}
+
+# Make sure other test runs have started too.
+sleep 1
+nlink=\$(ls -l $TEST_TMPDIR/counter | awk '{print \$2}')
+
+# 4 links = 3 jobs + $TEST_TMPDIR/counter
+if [[ "\$nlink" -gt 4 ]] ; then
+ echo found "\$nlink" hard links to file, want 4 max.
+ exit 1
+fi
+
+# Ensure that we don't remove before other runs have inspected the file.
+sleep 1
+rm \${z}
+
+EOF
+
+ chmod +x dir/test.sh
+
+ cat <<EOF > dir/BUILD
+sh_test(
+ name = "test",
+ srcs = [ "test.sh" ],
+ size = "small",
+ tags = [ "local" ],
+)
+EOF
+}
+
+function test_local_test_jobs_constrains_test_execution() {
+ create_test_files
+ # 3 local test jobs, so no more than 3 tests in parallel.
+ bazel test --local_test_jobs=3 --local_resources=10000,10,100 --runs_per_test=10 \
+ //dir:test
+}
+
+function test_no_local_test_jobs_causes_local_resources_to_constrain_test_execution() {
+ create_test_files
+ # unlimited local test jobs, so local resources enforces 3 tests in parallel.
+ bazel test --local_resources=10000,3,100 --runs_per_test=10 \
+ //dir:test
+}
+
+function test_local_test_jobs_exceeds_jobs_causes_warning() {
+ create_test_files
+ # 10 local test jobs, but only 3 jobs, so warning is printed, and only 3 tests run concurrently
+ bazel test --jobs=3 --local_test_jobs=10 --local_resources=10000,10,100 --runs_per_test=10 \
+ //dir:test >& $TEST_log
+
+ expect_log 'High value for --local_test_jobs'
+}
+
+function test_negative_local_test_jobs_causes_warning() {
+ create_test_files
+ bazel test --local_test_jobs=-1 --local_resources=10000,10,100 --runs_per_test=10 \
+ //dir:test >& $TEST_log && fail "Expected test failure"
+
+ expect_log 'Invalid parameter for --local_test_jobs'
+}
+
+run_suite "Tests for --local_test_jobs option."