Skip to content

Commit 9cd83cc

Browse files
authored
test(storage): deflake integration tests (#6792)
Use a different instance of the emulator to run the **emulator** tests vs. the tests that **use** the emulator. The emulator tests intentionally crash some of the emulator workers, which then causes problems for the regular tests. Note that the emulator tests themselves are still flaky, but they are very fast so using `--flake-test_attempts` mostly avoids the problem.
1 parent 079c926 commit 9cd83cc

4 files changed

Lines changed: 59 additions & 13 deletions

File tree

ci/cloudbuild/builds/lib/integration.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ function integration::bazel_with_emulators() {
167167
"google/cloud/pubsub/ci/${EMULATOR_SCRIPT}" \
168168
bazel "${verb}" "${args[@]}"
169169

170+
io::log_h2 "Running Storage Emulator integration tests"
171+
"google/cloud/storage/emulator/ci/run_integration_tests_bazel.sh" \
172+
bazel "${args[@]}"
173+
170174
io::log_h2 "Running Storage integration tests (with emulator)"
171175
"google/cloud/storage/ci/${EMULATOR_SCRIPT}" \
172176
bazel "${verb}" "${args[@]}"

google/cloud/storage/ci/run_integration_tests_emulator_bazel.sh

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,6 @@ pushd "${HOME}" >/dev/null
6666
start_emulator 8585 8000
6767
popd >/dev/null
6868

69-
# Run the unittests of the emulator before running integration tests.
70-
# TODO(#6641): Remove the --flaky_test_attempts flag once the flakiness is fixed.
71-
"${BAZEL_BIN}" test "${bazel_test_args[@]}" "//google/cloud/storage/emulator:test_utils" \
72-
"//google/cloud/storage/emulator:test_gcs" \
73-
"--flaky_test_attempts=5" \
74-
"--test_env=CLOUD_STORAGE_EMULATOR_ENDPOINT=${CLOUD_STORAGE_EMULATOR_ENDPOINT}"
75-
exit_status=$?
76-
77-
if [[ "$exit_status" -ne 0 ]]; then
78-
exit "${exit_status}"
79-
fi
80-
8169
excluded_targets+=(
8270
# This test does not work with Bazel, because it depends on dynamic loading
8371
# and some CMake magic. It is also skipped against production, so most Bazel
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eu
17+
18+
source "$(dirname "$0")/../../../../../ci/lib/init.sh"
19+
source module /ci/etc/integration-tests-config.sh
20+
source module /google/cloud/storage/tools/run_emulator_utils.sh
21+
22+
if [[ $# -lt 1 ]]; then
23+
echo "Usage: $(basename "$0") <bazel-program> [bazel-test-args]"
24+
exit 1
25+
fi
26+
27+
# Configure run_emulators_utils.sh to find the instance admin emulator.
28+
BAZEL_BIN="$1"
29+
shift
30+
31+
bazel_test_args=("$@")
32+
33+
# `start_emulator` creates unsightly *.log files in the current directory
34+
# (which is ${PROJECT_ROOT}) and we cannot use a subshell because we want the
35+
# environment variables that it sets.
36+
pushd "${HOME}" >/dev/null
37+
# Start the emulator on a fixed port, otherwise the Bazel cache gets
38+
# invalidated on each run.
39+
start_emulator 8586 8587
40+
popd >/dev/null
41+
42+
# Run the unittests of the emulator before running integration tests.
43+
# TODO(#6641): Remove the --flaky_test_attempts flag once the flakiness is fixed.
44+
"${BAZEL_BIN}" test "${bazel_test_args[@]}" \
45+
"--flaky_test_attempts=5" \
46+
"--test_env=CLOUD_STORAGE_EMULATOR_ENDPOINT=${CLOUD_STORAGE_EMULATOR_ENDPOINT}" \
47+
-- "//google/cloud/storage/emulator:test_utils" "//google/cloud/storage/emulator:test_gcs"
48+
exit_status=$?
49+
50+
if [[ "${exit_status}" -ne 0 ]]; then
51+
cat "${HOME}/gcs_emulator.log"
52+
fi
53+
54+
exit "${exit_status}"

google/cloud/storage/tools/run_emulator_utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ start_emulator() {
8989

9090
delay=1
9191
connected=no
92-
for attempt in $(seq 1 8); do
92+
for _ in $(seq 1 8); do
9393
if curl "${HTTPBIN_ENDPOINT}/get" >/dev/null 2>&1; then
9494
connected=yes
9595
break

0 commit comments

Comments
 (0)