2022-05-11 16:39:36 +02:00
|
|
|
---
|
|
|
|
title: SyTest
|
|
|
|
parent: Development
|
|
|
|
permalink: /development/sytest
|
|
|
|
---
|
|
|
|
|
2019-05-24 16:00:03 +02:00
|
|
|
# SyTest
|
|
|
|
|
|
|
|
Dendrite uses [SyTest](https://github.com/matrix-org/sytest) for its
|
2019-06-21 17:49:37 +02:00
|
|
|
integration testing. When creating a new PR, add the test IDs (see below) that
|
2020-01-22 14:31:22 +01:00
|
|
|
your PR should allow to pass to `sytest-whitelist` in dendrite's root
|
|
|
|
directory. Not all PRs need to make new tests pass. If we find your PR should
|
|
|
|
be making a test pass we may ask you to add to that file, as generally
|
|
|
|
Dendrite's progress can be tracked through the amount of SyTest tests it
|
|
|
|
passes.
|
2019-06-21 17:49:37 +02:00
|
|
|
|
|
|
|
## Finding out which tests to add
|
|
|
|
|
2020-08-25 09:11:41 +02:00
|
|
|
We recommend you run the tests locally by using the SyTest docker image.
|
|
|
|
After running the tests, a script will print the tests you need to add to
|
|
|
|
`sytest-whitelist`.
|
2019-06-21 17:49:37 +02:00
|
|
|
|
|
|
|
You should proceed after you see no build problems for dendrite after running:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
./build.sh
|
|
|
|
```
|
|
|
|
|
2020-08-25 09:11:41 +02:00
|
|
|
If you are fixing an issue marked with
|
|
|
|
[Are We Synapse Yet](https://github.com/matrix-org/dendrite/labels/are-we-synapse-yet)
|
|
|
|
then there will be a list of Sytests that you should add to the whitelist when you
|
|
|
|
have fixed that issue. This MUST be included in your PR to ensure that the issue
|
|
|
|
is fully resolved.
|
|
|
|
|
2020-04-12 14:48:24 +02:00
|
|
|
### Using the SyTest Docker image
|
|
|
|
|
2020-08-25 09:11:41 +02:00
|
|
|
**We strongly recommend using the Docker image to run Sytest.**
|
|
|
|
|
2020-04-12 14:48:24 +02:00
|
|
|
Use the following commands to pull the latest SyTest image and run the tests:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
docker pull matrixdotorg/sytest-dendrite
|
|
|
|
docker run --rm -v /path/to/dendrite/:/src/ -v /path/to/log/output/:/logs/ matrixdotorg/sytest-dendrite
|
|
|
|
```
|
|
|
|
|
|
|
|
`/path/to/dendrite/` should be replaced with the actual path to your dendrite
|
|
|
|
source code. The test results TAP file and homeserver logging output will go to
|
|
|
|
`/path/to/log/output`. The output of the command should tell you if you need to
|
|
|
|
add any tests to `sytest-whitelist`.
|
|
|
|
|
|
|
|
When debugging, the following Docker `run` options may also be useful:
|
2022-05-11 16:39:36 +02:00
|
|
|
|
2020-04-12 14:48:24 +02:00
|
|
|
* `-v /path/to/sytest/:/sytest/`: Use your local SyTest repository at
|
|
|
|
`/path/to/sytest` instead of pulling from GitHub. This is useful when you want
|
|
|
|
to speed things up or make modifications to SyTest.
|
2020-08-25 09:11:41 +02:00
|
|
|
* `-v "/path/to/gopath/:/gopath"`: Use your local `GOPATH` so you don't need to
|
|
|
|
re-download packages on every run.
|
2020-04-12 14:48:24 +02:00
|
|
|
* `--entrypoint bash`: Prevent the container from automatically starting the
|
|
|
|
tests. When used, you need to manually run `/bootstrap.sh dendrite` inside
|
|
|
|
the container to start them.
|
2020-08-25 09:11:41 +02:00
|
|
|
* `-e "DENDRITE_TRACE_HTTP=1"`: Adds HTTP tracing to server logs.
|
|
|
|
* `-e "DENDRITE_TRACE_INTERNAL=1"`: Adds roomserver internal API tracing to
|
|
|
|
server logs.
|
|
|
|
|
|
|
|
The docker command also supports a single positional argument for the test file to
|
|
|
|
run, so you can run a single `.pl` file rather than the whole test suite. For example:
|
2022-05-11 16:39:36 +02:00
|
|
|
|
2020-08-25 09:11:41 +02:00
|
|
|
```
|
|
|
|
docker run --rm --name sytest -v "/Users/kegan/github/sytest:/sytest"
|
|
|
|
-v "/Users/kegan/github/dendrite:/src" -v "/Users/kegan/logs:/logs"
|
|
|
|
-v "/Users/kegan/go/:/gopath" -e "POSTGRES=1" -e "DENDRITE_TRACE_HTTP=1"
|
|
|
|
matrixdotorg/sytest-dendrite:latest tests/50federation/40devicelists.pl
|
|
|
|
```
|
2020-04-12 14:48:24 +02:00
|
|
|
|
2019-06-21 17:49:37 +02:00
|
|
|
### Manually Setting up SyTest
|
|
|
|
|
2020-08-25 09:11:41 +02:00
|
|
|
**We advise AGAINST using manual SyTest setups.**
|
|
|
|
|
2020-04-12 14:48:24 +02:00
|
|
|
If you don't want to use the Docker image, you can also run SyTest by hand. Make
|
|
|
|
sure you have Perl 5 or above, and get SyTest with:
|
2019-06-21 17:49:37 +02:00
|
|
|
|
|
|
|
(Note that this guide assumes your SyTest checkout is next to your
|
|
|
|
`dendrite` checkout.)
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git clone -b develop https://github.com/matrix-org/sytest
|
|
|
|
cd sytest
|
|
|
|
./install-deps.pl
|
|
|
|
```
|
|
|
|
|
|
|
|
Set up the database:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
sudo -u postgres psql -c "CREATE USER dendrite PASSWORD 'itsasecret'"
|
2020-12-01 17:59:47 +01:00
|
|
|
sudo -u postgres psql -c "ALTER USER dendrite CREATEDB"
|
2020-04-12 14:48:24 +02:00
|
|
|
for i in dendrite0 dendrite1 sytest_template; do sudo -u postgres psql -c "CREATE DATABASE $i OWNER dendrite;"; done
|
2019-06-21 17:49:37 +02:00
|
|
|
mkdir -p "server-0"
|
|
|
|
cat > "server-0/database.yaml" << EOF
|
|
|
|
args:
|
|
|
|
user: dendrite
|
2020-04-12 14:48:24 +02:00
|
|
|
password: itsasecret
|
|
|
|
database: dendrite0
|
|
|
|
host: 127.0.0.1
|
|
|
|
sslmode: disable
|
|
|
|
type: pg
|
|
|
|
EOF
|
|
|
|
mkdir -p "server-1"
|
|
|
|
cat > "server-1/database.yaml" << EOF
|
|
|
|
args:
|
|
|
|
user: dendrite
|
|
|
|
password: itsasecret
|
|
|
|
database: dendrite1
|
2019-06-21 17:49:37 +02:00
|
|
|
host: 127.0.0.1
|
2020-02-11 14:53:00 +01:00
|
|
|
sslmode: disable
|
2019-06-21 17:49:37 +02:00
|
|
|
type: pg
|
|
|
|
EOF
|
|
|
|
```
|
|
|
|
|
|
|
|
Run the tests:
|
|
|
|
|
|
|
|
```sh
|
2020-04-12 14:48:24 +02:00
|
|
|
POSTGRES=1 ./run-tests.pl -I Dendrite::Monolith -d ../dendrite/bin -W ../dendrite/sytest-whitelist -O tap --all | tee results.tap
|
2019-06-21 17:49:37 +02:00
|
|
|
```
|
|
|
|
|
2020-04-12 14:48:24 +02:00
|
|
|
where `tee` lets you see the results while they're being piped to the file, and
|
|
|
|
`POSTGRES=1` enables testing with PostgeSQL. If the `POSTGRES` environment
|
|
|
|
variable is not set or is set to 0, SyTest will fall back to SQLite 3. For more
|
2022-05-11 16:39:36 +02:00
|
|
|
flags and options, see <https://github.com/matrix-org/sytest#running>.
|
2019-06-21 17:49:37 +02:00
|
|
|
|
|
|
|
Once the tests are complete, run the helper script to see if you need to add
|
2020-04-12 14:48:24 +02:00
|
|
|
any newly passing test names to `sytest-whitelist` in the project's root
|
|
|
|
directory:
|
2019-06-21 17:49:37 +02:00
|
|
|
|
|
|
|
```sh
|
2020-01-22 14:31:22 +01:00
|
|
|
../dendrite/show-expected-fail-tests.sh results.tap ../dendrite/sytest-whitelist ../dendrite/sytest-blacklist
|
2019-06-21 17:49:37 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
If the script prints nothing/exits with 0, then you're good to go.
|