complement.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. # If we're using workers, modify the docker files slightly.
  42. if [[ -n "$WORKERS" ]]; then
  43. # Build the workers docker image (from the base Synapse image).
  44. docker build -t matrixdotorg/synapse-workers -f "docker/Dockerfile-workers" .
  45. export COMPLEMENT_BASE_IMAGE=complement-synapse-workers
  46. COMPLEMENT_DOCKERFILE=SynapseWorkers.Dockerfile
  47. # And provide some more configuration to complement.
  48. # It can take quite a while to spin up a worker-mode Synapse for the first
  49. # time (the main problem is that we start 14 python processes for each test,
  50. # and complement likes to do two of them in parallel).
  51. export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=120
  52. # ... and it takes longer than 10m to run the whole suite.
  53. extra_test_args+=("-timeout=60m")
  54. else
  55. export COMPLEMENT_BASE_IMAGE=complement-synapse
  56. COMPLEMENT_DOCKERFILE=Dockerfile
  57. fi
  58. # Build the Complement image from the Synapse image we just built.
  59. docker build -t $COMPLEMENT_BASE_IMAGE -f "docker/complement/$COMPLEMENT_DOCKERFILE" "docker/complement"
  60. # Run the tests!
  61. echo "Images built; running complement"
  62. cd "$COMPLEMENT_DIR"
  63. go test -v -tags synapse_blacklist,msc2716,msc3030,faster_joins -count=1 "${extra_test_args[@]}" "$@" ./tests/...