2021-03-31 06:58:12 -04:00
|
|
|
#!/usr/bin/env bash
|
2020-09-29 08:47:47 -04:00
|
|
|
# This script is designed for developers who want to test their code
|
|
|
|
# against Complement.
|
|
|
|
#
|
|
|
|
# It makes a Synapse image which represents the current checkout,
|
2021-03-31 06:58:12 -04:00
|
|
|
# builds a synapse-complement image on top, then runs tests with it.
|
|
|
|
#
|
2022-02-23 05:06:18 -05:00
|
|
|
# By default the script will fetch the latest Complement main branch and
|
2021-03-31 06:58:12 -04:00
|
|
|
# run tests with that. This can be overridden to use a custom Complement
|
|
|
|
# checkout by setting the COMPLEMENT_DIR environment variable to the
|
2022-01-20 08:04:58 -05:00
|
|
|
# filepath of a local Complement checkout or by setting the COMPLEMENT_REF
|
|
|
|
# environment variable to pull a different branch or commit.
|
2021-03-31 06:58:12 -04:00
|
|
|
#
|
2021-05-24 15:32:45 -04:00
|
|
|
# By default Synapse is run in monolith mode. This can be overridden by
|
|
|
|
# setting the WORKERS environment variable.
|
|
|
|
#
|
2021-03-31 06:58:12 -04:00
|
|
|
# A regular expression of test method names can be supplied as the first
|
|
|
|
# argument to the script. Complement will then only run those tests. If
|
|
|
|
# no regex is supplied, all tests are run. For example;
|
|
|
|
#
|
2022-06-09 07:21:15 -04:00
|
|
|
# ./complement.sh -run "TestOutboundFederation(Profile|Send)"
|
2021-03-31 06:58:12 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
# Exit if a line returns a non-zero exit code
|
|
|
|
set -e
|
2020-09-29 08:47:47 -04:00
|
|
|
|
2022-01-12 05:37:57 -05:00
|
|
|
# enable buildkit for the docker builds
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
2021-03-31 06:58:12 -04:00
|
|
|
# Change to the repository root
|
2021-11-17 09:04:50 -05:00
|
|
|
cd "$(dirname $0)/.."
|
2020-09-29 08:47:47 -04:00
|
|
|
|
2021-03-31 06:58:12 -04:00
|
|
|
# Check for a user-specified Complement checkout
|
|
|
|
if [[ -z "$COMPLEMENT_DIR" ]]; then
|
2022-02-23 05:06:18 -05:00
|
|
|
COMPLEMENT_REF=${COMPLEMENT_REF:-main}
|
2022-01-20 08:04:58 -05:00
|
|
|
echo "COMPLEMENT_DIR not set. Fetching Complement checkout from ${COMPLEMENT_REF}..."
|
|
|
|
wget -Nq https://github.com/matrix-org/complement/archive/${COMPLEMENT_REF}.tar.gz
|
|
|
|
tar -xzf ${COMPLEMENT_REF}.tar.gz
|
|
|
|
COMPLEMENT_DIR=complement-${COMPLEMENT_REF}
|
|
|
|
echo "Checkout available at 'complement-${COMPLEMENT_REF}'"
|
2021-03-31 06:58:12 -04:00
|
|
|
fi
|
|
|
|
|
2021-08-25 10:18:23 -04:00
|
|
|
# Build the base Synapse image from the local checkout
|
|
|
|
docker build -t matrixdotorg/synapse -f "docker/Dockerfile" .
|
|
|
|
|
2022-06-08 05:57:05 -04:00
|
|
|
# Build the workers docker image (from the base Synapse image we just built).
|
|
|
|
docker build -t matrixdotorg/synapse-workers -f "docker/Dockerfile-workers" .
|
|
|
|
|
|
|
|
# Build the unified Complement image (from the worker Synapse image we just built).
|
|
|
|
docker build -t complement-synapse \
|
|
|
|
-f "docker/complement/Dockerfile" "docker/complement"
|
|
|
|
|
|
|
|
export COMPLEMENT_BASE_IMAGE=complement-synapse
|
|
|
|
|
2022-05-09 17:41:06 -04:00
|
|
|
extra_test_args=()
|
|
|
|
|
2022-05-24 12:50:50 -04:00
|
|
|
test_tags="synapse_blacklist,msc2716,msc3030,msc3787"
|
2022-05-23 12:27:05 -04:00
|
|
|
|
2022-06-08 05:57:05 -04:00
|
|
|
# All environment variables starting with PASS_ will be shared.
|
|
|
|
# (The prefix is stripped off before reaching the container.)
|
|
|
|
export COMPLEMENT_SHARE_ENV_PREFIX=PASS_
|
|
|
|
|
2021-05-24 15:32:45 -04:00
|
|
|
if [[ -n "$WORKERS" ]]; then
|
2022-06-08 05:57:05 -04:00
|
|
|
# Use workers.
|
|
|
|
export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS=true
|
2021-08-25 10:18:23 -04:00
|
|
|
|
2022-06-08 05:57:05 -04:00
|
|
|
# Workers can only use Postgres as a database.
|
|
|
|
export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres
|
2022-04-11 06:39:28 -04:00
|
|
|
|
2021-05-24 15:32:45 -04:00
|
|
|
# And provide some more configuration to complement.
|
2022-05-09 17:41:06 -04:00
|
|
|
|
|
|
|
# It can take quite a while to spin up a worker-mode Synapse for the first
|
|
|
|
# time (the main problem is that we start 14 python processes for each test,
|
|
|
|
# and complement likes to do two of them in parallel).
|
|
|
|
export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=120
|
|
|
|
|
|
|
|
# ... and it takes longer than 10m to run the whole suite.
|
|
|
|
extra_test_args+=("-timeout=60m")
|
2021-05-24 15:32:45 -04:00
|
|
|
else
|
2022-06-08 05:57:05 -04:00
|
|
|
export PASS_SYNAPSE_COMPLEMENT_USE_WORKERS=
|
|
|
|
if [[ -n "$POSTGRES" ]]; then
|
|
|
|
export PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres
|
|
|
|
else
|
|
|
|
export PASS_SYNAPSE_COMPLEMENT_DATABASE=sqlite
|
|
|
|
fi
|
2022-05-23 12:27:05 -04:00
|
|
|
|
|
|
|
# We only test faster room joins on monoliths, because they are purposefully
|
|
|
|
# being developed without worker support to start with.
|
|
|
|
test_tags="$test_tags,faster_joins"
|
2021-05-24 15:32:45 -04:00
|
|
|
fi
|
|
|
|
|
2021-03-31 06:58:12 -04:00
|
|
|
# Run the tests!
|
2022-01-12 05:37:57 -05:00
|
|
|
echo "Images built; running complement"
|
2022-04-11 06:39:28 -04:00
|
|
|
cd "$COMPLEMENT_DIR"
|
2022-05-23 12:27:05 -04:00
|
|
|
|
|
|
|
go test -v -tags $test_tags -count=1 "${extra_test_args[@]}" "$@" ./tests/...
|