Skip to content

Commit 54c93a1

Browse files
Export SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES from scripts-dev/complement.sh (#19208)
This is useful as someone downstream can source the `scripts-dev/complement.sh` script and run the same set of tests as Synapse: ```bash # Grab the test packages supported by Synapse. # # --fast: Skip rebuilding the docker images, # --build-only: Will only build Docker images but because we also used `--fast`, it won't do anything. # `>/dev/null` to redirect stdout to `/dev/null` to get rid of the `echo` logs from the script. test_packages=$(source ${SYNAPSE_DIR}/scripts-dev/complement.sh --fast --build-only >/dev/null && echo "$SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES") echo $test_packages ``` This is spawning from wanting to run the same set of Complement tests in the https://github.com/element-hq/synapse-rust-apps project.
1 parent e39fba6 commit 54c93a1

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

changelog.d/19208.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Export `SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES` environment variable from `scripts-dev/complement.sh`.

scripts-dev/complement.sh

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ For help on arguments to 'go test', run 'go help testflag'.
7272
EOF
7373
}
7474

75+
# We use a function to wrap the script logic so that we can use `return` to exit early
76+
# if needed. This is particularly useful so that this script can be sourced by other
77+
# scripts without exiting the calling subshell (composable). This allows us to share
78+
# variables like `SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES` with other scripts.
79+
#
80+
# Returns an exit code of 0 on success, or 1 on failure.
7581
main() {
7682
# parse our arguments
7783
skip_docker_build=""
@@ -204,21 +210,12 @@ main() {
204210
echo_if_github "::endgroup::"
205211

206212
fi
213+
214+
echo "Docker images built."
215+
else
216+
echo "Skipping Docker image build as requested."
207217
fi
208218

209-
if [ -n "$skip_complement_run" ]; then
210-
echo "Skipping Complement run as requested."
211-
return 0
212-
fi
213-
214-
export COMPLEMENT_BASE_IMAGE=complement-synapse
215-
if [ -n "$use_editable_synapse" ]; then
216-
export COMPLEMENT_BASE_IMAGE=complement-synapse-editable
217-
export COMPLEMENT_HOST_MOUNTS="$editable_mount"
218-
fi
219-
220-
extra_test_args=()
221-
222219
test_packages=(
223220
./tests/csapi
224221
./tests
@@ -234,6 +231,16 @@ main() {
234231
./tests/msc4306
235232
)
236233

234+
# Export the list of test packages as a space-separated environment variable, so other
235+
# scripts can use it.
236+
export SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES="${test_packages[@]}"
237+
238+
export COMPLEMENT_BASE_IMAGE=complement-synapse
239+
if [ -n "$use_editable_synapse" ]; then
240+
export COMPLEMENT_BASE_IMAGE=complement-synapse-editable
241+
export COMPLEMENT_HOST_MOUNTS="$editable_mount"
242+
fi
243+
237244
# Enable dirty runs, so tests will reuse the same container where possible.
238245
# This significantly speeds up tests, but increases the possibility of test pollution.
239246
export COMPLEMENT_ENABLE_DIRTY_RUNS=1
@@ -242,8 +249,18 @@ main() {
242249
# (The prefix is stripped off before reaching the container.)
243250
export COMPLEMENT_SHARE_ENV_PREFIX=PASS_
244251

252+
# * -count=1: Only run tests once, and disable caching for tests.
253+
# * -v: Output test logs, even if those tests pass.
254+
# * -tags=synapse_blacklist: Enable the `synapse_blacklist` build tag, which is
255+
# necessary for `runtime.Synapse` checks/skips to work in the tests
256+
test_args=(
257+
-v
258+
-tags="synapse_blacklist"
259+
-count=1
260+
)
261+
245262
# It takes longer than 10m to run the whole suite.
246-
extra_test_args+=("-timeout=60m")
263+
test_args+=("-timeout=60m")
247264

248265
if [[ -n "$WORKERS" ]]; then
249266
# Use workers.
@@ -295,11 +312,15 @@ main() {
295312
# particularly tricky.
296313
export PASS_SYNAPSE_LOG_TESTING=1
297314

315+
if [ -n "$skip_complement_run" ]; then
316+
echo "Skipping Complement run as requested."
317+
return 0
318+
fi
319+
298320
# Run the tests!
299-
echo "Images built; running complement with ${extra_test_args[@]} $@ ${test_packages[@]}"
321+
echo "Running Complement with ${test_args[@]} $@ ${test_packages[@]}"
300322
cd "$COMPLEMENT_DIR"
301-
302-
go test -v -tags "synapse_blacklist" -count=1 "${extra_test_args[@]}" "$@" "${test_packages[@]}"
323+
go test "${test_args[@]}" "$@" "${test_packages[@]}"
303324
}
304325

305326
main "$@"

0 commit comments

Comments
 (0)