Skip to content

Commit 44d66a4

Browse files
authored
ci: use emulator for Spanner and Bazel (#6812)
1 parent e9b7bff commit 44d66a4

3 files changed

Lines changed: 60 additions & 5 deletions

File tree

ci/cloudbuild/builds/lib/integration.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ function integration::bazel_with_emulators() {
175175
"google/cloud/storage/ci/${EMULATOR_SCRIPT}" \
176176
bazel "${verb}" "${args[@]}"
177177

178-
io::log_h2 "Running Spanner integration tests"
179-
bazel "${verb}" "${args[@]}" --test_tag_filters=integration-test \
180-
google/cloud/spanner/...
178+
io::log_h2 "Running Spanner integration tests (with emulator)"
179+
"google/cloud/spanner/ci/${EMULATOR_SCRIPT}" \
180+
bazel "${verb}" "${args[@]}"
181181

182182
# We retry these tests because the emulator crashes due to #441.
183183
io::log_h2 "Running Bigtable integration tests (with emulator)"

google/cloud/spanner/ci/lib/spanner_emulator.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ function spanner_emulator::start() {
5353
return 1
5454
fi
5555

56+
local emulator_port=0
57+
if [[ $# -ge 1 ]]; then
58+
emulator_port=$1
59+
fi
60+
5661
# We cannot use `gcloud beta emulators spanner start` because there is no way
5762
# to kill the emulator at the end using that command.
5863
readonly SPANNER_EMULATOR_CMD="${CLOUD_SDK_LOCATION}/bin/cloud_spanner_emulator/emulator_main"
@@ -63,10 +68,10 @@ function spanner_emulator::start() {
6368

6469
# The tests typically run in a Docker container, where the ports are largely
6570
# free; when using in manual tests, you can set EMULATOR_PORT.
66-
"${SPANNER_EMULATOR_CMD}" --host_port localhost:0 >emulator.log 2>&1 </dev/null &
71+
"${SPANNER_EMULATOR_CMD}" --host_port "localhost:${emulator_port}" >emulator.log 2>&1 </dev/null &
6772
SPANNER_EMULATOR_PID=$!
6873

69-
local -r emulator_port="$(spanner_emulator::internal::read_emulator_port emulator.log)"
74+
emulator_port="$(spanner_emulator::internal::read_emulator_port emulator.log)"
7075
if [[ "${emulator_port}" = "0" ]]; then
7176
echo "Cannot determine Cloud Spanner emulator port." >&2
7277
spanner_emulator::kill
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 /ci/lib/io.sh
21+
source module /google/cloud/spanner/ci/lib/spanner_emulator.sh
22+
23+
if [[ $# -lt 2 ]]; then
24+
echo "Usage: $(basename "$0") <bazel-program> <bazel-verb> [bazel-test-args]"
25+
exit 1
26+
fi
27+
28+
BAZEL_BIN="$1"
29+
shift
30+
BAZEL_VERB="$1"
31+
shift
32+
bazel_test_args=("$@")
33+
34+
# Start the emulator and arranges to kill it, run in $HOME because
35+
# pubsub_emulator::start creates unsightly *.log files in the workspace
36+
# otherwise. Use a fixed port so Bazel can cache the test results.
37+
pushd "${HOME}" >/dev/null
38+
spanner_emulator::start 8787
39+
popd
40+
trap spanner_emulator::kill EXIT
41+
42+
"${BAZEL_BIN}" "${BAZEL_VERB}" "${bazel_test_args[@]}" \
43+
--test_env="SPANNER_EMULATOR_HOST=${SPANNER_EMULATOR_HOST}" \
44+
--test_env="GOOGLE_CLOUD_CPP_AUTO_RUN_EXAMPLES=yes" \
45+
--test_env="GOOGLE_CLOUD_CPP_EXPERIMENTAL_LOG_CONFIG=lastN,100,WARNING" \
46+
--test_env="GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc,rpc-streams" \
47+
--test_env="GOOGLE_CLOUD_CPP_TRACING_OPTIONS=truncate_string_field_longer_than=512" \
48+
--test_env="GOOGLE_CLOUD_CPP_SPANNER_SLOW_INTEGRATION_TESTS=instance,backup" \
49+
--test_tag_filters="integration-test" -- \
50+
"//google/cloud/spanner/...:all"

0 commit comments

Comments
 (0)