Skip to content

Commit 66825c2

Browse files
author
Takashi Matsuo
authored
testing: start using btlr (#3959)
* testing: start using btlr The binary is at gs://cloud-devrel-kokoro-resources/btlr/v0.0.1/btlr * add period after DIFF_FROM * use array for btlr args * fix websocket tests * add debug message * wait longer for the server to spin up * dlp: bump the wait timeout to 10 minutes * [run] copy noxfile.py to child directory to avoid gcloud issue * [iam] fix: only display description when the key exists * use uuid4 instead of uuid1 * [iot] testing: use the same format for registry id * Stop asserting Out of memory not in the output * fix missing imports * [dns] testing: more retries with delay * [dlp] testing: longer timeout * use the max-concurrency flag * use 30 workers * [monitoring] use multiple projects * [dlp] testing: longer timeout
1 parent feab283 commit 66825c2

File tree

25 files changed

+849
-112
lines changed

25 files changed

+849
-112
lines changed

.kokoro/tests/run_single_test.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# Copyright 2020 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+
# Run the test, assuming it's already in the target directory.
17+
# Requirements:
18+
# The current directory is the test target directory.
19+
# Env var `PROJECT_ROOT` is defined.
20+
21+
echo "------------------------------------------------------------"
22+
echo "- testing ${PWD}"
23+
echo "------------------------------------------------------------"
24+
25+
# If no local noxfile exists, copy the one from root
26+
if [[ ! -f "noxfile.py" ]]; then
27+
PARENT_DIR=$(cd ../ && pwd)
28+
while [[ "$PARENT_DIR" != "${PROJECT_ROOT}" && \
29+
! -f "$PARENT_DIR/noxfile-template.py" ]];
30+
do
31+
PARENT_DIR=$(dirname "$PARENT_DIR")
32+
done
33+
cp "$PARENT_DIR/noxfile-template.py" "./noxfile.py"
34+
echo -e "\n Using noxfile-template from parent folder ($PARENT_DIR). \n"
35+
cleanup_noxfile=1
36+
else
37+
cleanup_noxfile=0
38+
fi
39+
40+
# Use nox to execute the tests for the project.
41+
nox -s "$RUN_TESTS_SESSION"
42+
EXIT=$?
43+
44+
# If REPORT_TO_BUILD_COP_BOT is set to "true", send the test log
45+
# to the Build Cop Bot.
46+
# See:
47+
# https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
48+
if [[ "${REPORT_TO_BUILD_COP_BOT:-}" == "true" ]]; then
49+
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
50+
$KOKORO_GFILE_DIR/linux_amd64/buildcop
51+
fi
52+
53+
if [[ "${EXIT}" -ne 0 ]]; then
54+
echo -e "\n Testing failed: Nox returned a non-zero exit code. \n"
55+
else
56+
echo -e "\n Testing completed.\n"
57+
fi
58+
59+
# Remove noxfile.py if we copied.
60+
if [[ $cleanup_noxfile -eq 1 ]]; then
61+
rm noxfile.py
62+
fi
63+
64+
exit ${EXIT}

.kokoro/tests/run_tests.sh

Lines changed: 31 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ fi
3939
# `--only-diff-head` will only run tests on project changes from the
4040
# previous commit.
4141
if [[ $* == *--only-diff-head* ]]; then
42-
DIFF_FROM="HEAD~.."
42+
set +e
43+
git diff --quiet "HEAD~.." .kokoro/tests .kokoro/docker \
44+
.kokoro/trampoline_v2.sh
45+
CHANGED=$?
46+
set -e
47+
if [[ "${CHANGED}" -eq 0 ]]; then
48+
DIFF_FROM="HEAD~.."
49+
else
50+
echo "Changes to test driver files detected. Running full tests."
51+
fi
4352
fi
4453

4554
if [[ -z "${PROJECT_ROOT:-}" ]]; then
@@ -94,97 +103,32 @@ set +e
94103
RTN=0
95104
ROOT=$(pwd)
96105

97-
# Find all requirements.txt in the repository (may break on whitespace).
98-
for file in **/requirements.txt; do
99-
cd "$ROOT"
100-
# Navigate to the project folder.
101-
file=$(dirname "$file")
102-
cd "$file"
103-
104-
# First we look up the environment variable `RUN_TESTS_DIRS`. If
105-
# the value is set, we'll iterate through the colon separated
106-
# directory list. If the target directory is not under any
107-
# directory in the list, we skip this directory.
108-
# This environment variables are primarily for
109-
# `scripts/run_tests_local.sh`.
110-
#
111-
# The value must be a colon separated list of relative paths from
112-
# the project root.
113-
#
114-
# Example:
115-
# cdn:appengine/flexible
116-
# run tests for `cdn` and `appengine/flexible` directories.
117-
# logging/cloud-client
118-
# only run tests for `logging/cloud-client` directory.
119-
#
120-
if [[ -n "${RUN_TESTS_DIRS:-}" ]]; then
121-
match=0
122-
for d in $(echo "${RUN_TESTS_DIRS}" | tr ":" "\n"); do
123-
# If the current dir starts with one of the
124-
# RUN_TESTS_DIRS, we should run the tests.
125-
if [[ "${file}" = "${d}"* ]]; then
126-
match=1
127-
break
128-
fi
129-
done
130-
if [[ $match -eq 0 ]]; then
131-
continue
132-
fi
133-
fi
134-
# If $DIFF_FROM is set, use it to check for changes in this directory.
135-
if [[ -n "${DIFF_FROM:-}" ]]; then
136-
git diff --quiet "$DIFF_FROM" .
137-
CHANGED=$?
138-
if [[ "$CHANGED" -eq 0 ]]; then
139-
# echo -e "\n Skipping $file: no changes in folder.\n"
140-
continue
141-
fi
142-
fi
106+
test_prog="${PROJECT_ROOT}/.kokoro/tests/run_single_test.sh"
143107

144-
echo "------------------------------------------------------------"
145-
echo "- testing $file"
146-
echo "------------------------------------------------------------"
147-
148-
# If no local noxfile exists, copy the one from root
149-
if [[ ! -f "noxfile.py" ]]; then
150-
PARENT_DIR=$(cd ../ && pwd)
151-
while [[ "$PARENT_DIR" != "$ROOT" && ! -f "$PARENT_DIR/noxfile-template.py" ]];
152-
do
153-
PARENT_DIR=$(dirname "$PARENT_DIR")
154-
done
155-
cp "$PARENT_DIR/noxfile-template.py" "./noxfile.py"
156-
echo -e "\n Using noxfile-template from parent folder ($PARENT_DIR). \n"
157-
cleanup_noxfile=1
158-
else
159-
cleanup_noxfile=0
160-
fi
108+
btlr_args=(
109+
"run"
110+
"**/requirements.txt"
111+
"--max-concurrency"
112+
"30"
113+
)
161114

162-
# Use nox to execute the tests for the project.
163-
nox -s "$RUN_TESTS_SESSION"
164-
EXIT=$?
165-
166-
# If REPORT_TO_BUILD_COP_BOT is set to "true", send the test log
167-
# to the Build Cop Bot.
168-
# See:
169-
# https://github.com/googleapis/repo-automation-bots/tree/master/packages/buildcop.
170-
if [[ "${REPORT_TO_BUILD_COP_BOT:-}" == "true" ]]; then
171-
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
172-
$KOKORO_GFILE_DIR/linux_amd64/buildcop
173-
fi
115+
if [[ -n "${DIFF_FROM:-}" ]]; then
116+
btlr_args+=(
117+
"--git-diff"
118+
"${DIFF_FROM} ."
119+
)
120+
fi
174121

175-
if [[ $EXIT -ne 0 ]]; then
176-
RTN=1
177-
echo -e "\n Testing failed: Nox returned a non-zero exit code. \n"
178-
else
179-
echo -e "\n Testing completed.\n"
180-
fi
122+
btlr_args+=(
123+
"--"
124+
"${test_prog}"
125+
)
181126

182-
# Remove noxfile.py if we copied.
183-
if [[ $cleanup_noxfile -eq 1 ]]; then
184-
rm noxfile.py
185-
fi
127+
echo "testing/btlr" "${btlr_args[@]}"
128+
129+
testing/btlr "${btlr_args[@]}"
186130

187-
done
131+
RTN=$?
188132
cd "$ROOT"
189133

190134
# Remove secrets if we used decrypt-secrets.sh.

0 commit comments

Comments
 (0)