complement.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. # This script is designed for developers who want to test their code
  3. # against Complement.
  4. #
  5. # It makes a Synapse image which represents the current checkout,
  6. # builds a synapse-complement image on top, then runs tests with it.
  7. #
  8. # By default the script will fetch the latest Complement main branch and
  9. # run tests with that. This can be overridden to use a custom Complement
  10. # checkout by setting the COMPLEMENT_DIR environment variable to the
  11. # filepath of a local Complement checkout or by setting the COMPLEMENT_REF
  12. # environment variable to pull a different branch or commit.
  13. #
  14. # By default Synapse is run in monolith mode. This can be overridden by
  15. # setting the WORKERS environment variable.
  16. #
  17. # A regular expression of test method names can be supplied as the first
  18. # argument to the script. Complement will then only run those tests. If
  19. # no regex is supplied, all tests are run. For example;
  20. #
  21. # ./complement.sh "TestOutboundFederation(Profile|Send)"
  22. #
  23. # Exit if a line returns a non-zero exit code
  24. set -e
  25. # enable buildkit for the docker builds
  26. export DOCKER_BUILDKIT=1
  27. # Change to the repository root
  28. cd "$(dirname $0)/.."
  29. # Check for a user-specified Complement checkout
  30. if [[ -z "$COMPLEMENT_DIR" ]]; then
  31. COMPLEMENT_REF=${COMPLEMENT_REF:-main}
  32. echo "COMPLEMENT_DIR not set. Fetching Complement checkout from ${COMPLEMENT_REF}..."
  33. wget -Nq https://github.com/matrix-org/complement/archive/${COMPLEMENT_REF}.tar.gz
  34. tar -xzf ${COMPLEMENT_REF}.tar.gz
  35. COMPLEMENT_DIR=complement-${COMPLEMENT_REF}
  36. echo "Checkout available at 'complement-${COMPLEMENT_REF}'"
  37. fi
  38. # Build the base Synapse image from the local checkout
  39. docker build -t matrixdotorg/synapse -f "docker/Dockerfile" .
  40. extra_test_args=()
  41. test_tags="synapse_blacklist,msc2716,msc3030,msc3787"
  42. # If we're using workers, modify the docker files slightly.
  43. if [[ -n "$WORKERS" ]]; then
  44. # Build the workers docker image (from the base Synapse image).
  45. docker build -t matrixdotorg/synapse-workers -f "docker/Dockerfile-workers" .
  46. export COMPLEMENT_BASE_IMAGE=complement-synapse-workers
  47. COMPLEMENT_DOCKERFILE=SynapseWorkers.Dockerfile
  48. # And provide some more configuration to complement.
  49. # It can take quite a while to spin up a worker-mode Synapse for the first
  50. # time (the main problem is that we start 14 python processes for each test,
  51. # and complement likes to do two of them in parallel).
  52. export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=120
  53. # ... and it takes longer than 10m to run the whole suite.
  54. extra_test_args+=("-timeout=60m")
  55. else
  56. export COMPLEMENT_BASE_IMAGE=complement-synapse
  57. COMPLEMENT_DOCKERFILE=Dockerfile
  58. # We only test faster room joins on monoliths, because they are purposefully
  59. # being developed without worker support to start with.
  60. test_tags="$test_tags,faster_joins"
  61. fi
  62. # Build the Complement image from the Synapse image we just built.
  63. docker build -t $COMPLEMENT_BASE_IMAGE -f "docker/complement/$COMPLEMENT_DOCKERFILE" "docker/complement"
  64. # Run the tests!
  65. echo "Images built; running complement"
  66. cd "$COMPLEMENT_DIR"
  67. go test -v -tags $test_tags -count=1 "${extra_test_args[@]}" "$@" ./tests/...