Compare commits

...

4 Commits

Author SHA1 Message Date
Eric Eastwood
c75fb2eeb6 Add changelog 2025-11-20 17:36:21 -06:00
Eric Eastwood
ad94b9103e Use consistent indentation 2025-11-20 17:31:42 -06:00
Eric Eastwood
588c2b4db9 Use return instead of exit
This is useful so that the script can be sourced without exiting the calling subshell.
2025-11-20 17:29:07 -06:00
Eric Eastwood
573accd0df Run complement.sh logic as function
This is useful as later we can refactor the early `exit` calls to `return` calls
so that the script can be sourced without exiting the calling subshell.
2025-11-20 17:25:50 -06:00
2 changed files with 179 additions and 168 deletions

1
changelog.d/19209.misc Normal file
View File

@@ -0,0 +1 @@
Refactor `scripts-dev/complement.sh` logic to avoid `exit` to facilitate being able to source it from other scripts (composable).

View File

@@ -72,15 +72,16 @@ For help on arguments to 'go test', run 'go help testflag'.
EOF EOF
} }
# parse our arguments main() {
skip_docker_build="" # parse our arguments
skip_complement_run="" skip_docker_build=""
while [ $# -ge 1 ]; do skip_complement_run=""
while [ $# -ge 1 ]; do
arg=$1 arg=$1
case "$arg" in case "$arg" in
"-h") "-h")
usage usage
exit 1 return 1
;; ;;
"-f"|"--fast") "-f"|"--fast")
skip_docker_build=1 skip_docker_build=1
@@ -99,35 +100,35 @@ while [ $# -ge 1 ]; do
break break
esac esac
shift shift
done done
# enable buildkit for the docker builds # enable buildkit for the docker builds
export DOCKER_BUILDKIT=1 export DOCKER_BUILDKIT=1
# Determine whether to use the docker or podman container runtime. # Determine whether to use the docker or podman container runtime.
if [ -n "$PODMAN" ]; then if [ -n "$PODMAN" ]; then
export CONTAINER_RUNTIME=podman export CONTAINER_RUNTIME=podman
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock
export BUILDAH_FORMAT=docker export BUILDAH_FORMAT=docker
export COMPLEMENT_HOSTNAME_RUNNING_COMPLEMENT=host.containers.internal export COMPLEMENT_HOSTNAME_RUNNING_COMPLEMENT=host.containers.internal
else else
export CONTAINER_RUNTIME=docker export CONTAINER_RUNTIME=docker
fi fi
# Change to the repository root # Change to the repository root
cd "$(dirname $0)/.." cd "$(dirname $0)/.."
# Check for a user-specified Complement checkout # Check for a user-specified Complement checkout
if [[ -z "$COMPLEMENT_DIR" ]]; then if [[ -z "$COMPLEMENT_DIR" ]]; then
COMPLEMENT_REF=${COMPLEMENT_REF:-main} COMPLEMENT_REF=${COMPLEMENT_REF:-main}
echo "COMPLEMENT_DIR not set. Fetching Complement checkout from ${COMPLEMENT_REF}..." echo "COMPLEMENT_DIR not set. Fetching Complement checkout from ${COMPLEMENT_REF}..."
wget -Nq https://github.com/matrix-org/complement/archive/${COMPLEMENT_REF}.tar.gz wget -Nq https://github.com/matrix-org/complement/archive/${COMPLEMENT_REF}.tar.gz
tar -xzf ${COMPLEMENT_REF}.tar.gz tar -xzf ${COMPLEMENT_REF}.tar.gz
COMPLEMENT_DIR=complement-${COMPLEMENT_REF} COMPLEMENT_DIR=complement-${COMPLEMENT_REF}
echo "Checkout available at 'complement-${COMPLEMENT_REF}'" echo "Checkout available at 'complement-${COMPLEMENT_REF}'"
fi fi
if [ -n "$use_editable_synapse" ]; then if [ -n "$use_editable_synapse" ]; then
if [[ -e synapse/synapse_rust.abi3.so ]]; then if [[ -e synapse/synapse_rust.abi3.so ]]; then
# In an editable install, back up the host's compiled Rust module to prevent # In an editable install, back up the host's compiled Rust module to prevent
# inconvenience; the container will overwrite the module with its own copy. # inconvenience; the container will overwrite the module with its own copy.
@@ -156,9 +157,9 @@ if [ -n "$use_editable_synapse" ]; then
unset skip_docker_build unset skip_docker_build
fi fi
fi fi
fi fi
if [ -z "$skip_docker_build" ]; then if [ -z "$skip_docker_build" ]; then
if [ -n "$use_editable_synapse" ]; then if [ -n "$use_editable_synapse" ]; then
# Build a special image designed for use in development with editable # Build a special image designed for use in development with editable
@@ -203,22 +204,22 @@ if [ -z "$skip_docker_build" ]; then
echo_if_github "::endgroup::" echo_if_github "::endgroup::"
fi fi
fi fi
if [ -n "$skip_complement_run" ]; then if [ -n "$skip_complement_run" ]; then
echo "Skipping Complement run as requested." echo "Skipping Complement run as requested."
exit return 0
fi fi
export COMPLEMENT_BASE_IMAGE=complement-synapse export COMPLEMENT_BASE_IMAGE=complement-synapse
if [ -n "$use_editable_synapse" ]; then if [ -n "$use_editable_synapse" ]; then
export COMPLEMENT_BASE_IMAGE=complement-synapse-editable export COMPLEMENT_BASE_IMAGE=complement-synapse-editable
export COMPLEMENT_HOST_MOUNTS="$editable_mount" export COMPLEMENT_HOST_MOUNTS="$editable_mount"
fi fi
extra_test_args=() extra_test_args=()
test_packages=( test_packages=(
./tests/csapi ./tests/csapi
./tests ./tests
./tests/msc3874 ./tests/msc3874
@@ -231,20 +232,20 @@ test_packages=(
./tests/msc4140 ./tests/msc4140
./tests/msc4155 ./tests/msc4155
./tests/msc4306 ./tests/msc4306
) )
# Enable dirty runs, so tests will reuse the same container where possible. # Enable dirty runs, so tests will reuse the same container where possible.
# This significantly speeds up tests, but increases the possibility of test pollution. # This significantly speeds up tests, but increases the possibility of test pollution.
export COMPLEMENT_ENABLE_DIRTY_RUNS=1 export COMPLEMENT_ENABLE_DIRTY_RUNS=1
# All environment variables starting with PASS_ will be shared. # All environment variables starting with PASS_ will be shared.
# (The prefix is stripped off before reaching the container.) # (The prefix is stripped off before reaching the container.)
export COMPLEMENT_SHARE_ENV_PREFIX=PASS_ export COMPLEMENT_SHARE_ENV_PREFIX=PASS_
# It takes longer than 10m to run the whole suite. # It takes longer than 10m to run the whole suite.
extra_test_args+=("-timeout=60m") extra_test_args+=("-timeout=60m")
if [[ -n "$WORKERS" ]]; then if [[ -n "$WORKERS" ]]; then
# Use workers. # Use workers.
export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS=true export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS=true
@@ -260,26 +261,26 @@ if [[ -n "$WORKERS" ]]; then
# time (the main problem is that we start 14 python processes for each test, # time (the main problem is that we start 14 python processes for each test,
# and complement likes to do two of them in parallel). # and complement likes to do two of them in parallel).
export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=120 export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=120
else else
export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS= export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS=
if [[ -n "$POSTGRES" ]]; then if [[ -n "$POSTGRES" ]]; then
export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres
else else
export PASS_SYNAPSE_COMPLEMENT_DATABASE=sqlite export PASS_SYNAPSE_COMPLEMENT_DATABASE=sqlite
fi fi
fi fi
if [[ -n "$ASYNCIO_REACTOR" ]]; then if [[ -n "$ASYNCIO_REACTOR" ]]; then
# Enable the Twisted asyncio reactor # Enable the Twisted asyncio reactor
export PASS_SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=true export PASS_SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=true
fi fi
if [[ -n "$UNIX_SOCKETS" ]]; then if [[ -n "$UNIX_SOCKETS" ]]; then
# Enable full on Unix socket mode for Synapse, Redis and Postgresql # Enable full on Unix socket mode for Synapse, Redis and Postgresql
export PASS_SYNAPSE_USE_UNIX_SOCKET=1 export PASS_SYNAPSE_USE_UNIX_SOCKET=1
fi fi
if [[ -n "$SYNAPSE_TEST_LOG_LEVEL" ]]; then if [[ -n "$SYNAPSE_TEST_LOG_LEVEL" ]]; then
# Set the log level to what is desired # Set the log level to what is desired
export PASS_SYNAPSE_LOG_LEVEL="$SYNAPSE_TEST_LOG_LEVEL" export PASS_SYNAPSE_LOG_LEVEL="$SYNAPSE_TEST_LOG_LEVEL"
@@ -288,14 +289,23 @@ if [[ -n "$SYNAPSE_TEST_LOG_LEVEL" ]]; then
# Since this is just a test suite, this is fine and won't reveal anyone's # Since this is just a test suite, this is fine and won't reveal anyone's
# personal information # personal information
export PASS_SYNAPSE_LOG_SENSITIVE=1 export PASS_SYNAPSE_LOG_SENSITIVE=1
fi
# Log a few more useful things for a developer attempting to debug something
# particularly tricky.
export PASS_SYNAPSE_LOG_TESTING=1
# Run the tests!
echo "Images built; running complement with ${extra_test_args[@]} $@ ${test_packages[@]}"
cd "$COMPLEMENT_DIR"
go test -v -tags "synapse_blacklist" -count=1 "${extra_test_args[@]}" "$@" "${test_packages[@]}"
}
main "$@"
# For any non-zero exit code (indicating some sort of error happened), we want to exit
# with that code.
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi fi
# Log a few more useful things for a developer attempting to debug something
# particularly tricky.
export PASS_SYNAPSE_LOG_TESTING=1
# Run the tests!
echo "Images built; running complement with ${extra_test_args[@]} $@ ${test_packages[@]}"
cd "$COMPLEMENT_DIR"
go test -v -tags "synapse_blacklist" -count=1 "${extra_test_args[@]}" "$@" "${test_packages[@]}"