Skip to content

Commit 86bf4bb

Browse files
authored
Move CSAPI only tests to tests/csapi (#171)
* Move CSAPI only tests to tests/csapi This allows them to run in parallel with federation tests. * go test ./... * Update github actions * Track number of cpu cores on GH actions * Linting * Force 2 parallel executions * No more lscpu
1 parent 644ae7c commit 86bf4bb

20 files changed

+161
-26
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ jobs:
4242
steps:
4343
- uses: actions/checkout@v2
4444
- run: docker build -t homeserver -f dockerfiles/${{ matrix.homeserver }}.Dockerfile dockerfiles/
45-
- run: go test -v -tags "${{ matrix.tags }}" ./tests
45+
- run: go test -p 2 -v -tags "${{ matrix.tags }}" ./tests/...
4646
env:
4747
COMPLEMENT_BASE_IMAGE: homeserver

ONBOARDING.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ Adding `// sytest: ...` means `sytest_coverage.go` will know the test is convert
103103
when run! Use `go run sytest_coverage.go -v` to see the exact string to use, as they may be different to the one produced
104104
by an actual sytest run due to parameterised tests.
105105

106+
### Where should I put new tests?
107+
108+
If the test *only* has CS API calls, then put it in `/tests/csapi`. If the test involves both CS API and Federation, or just Federation, put it in `/tests`.
109+
This is because of how parallelisation works currently. All federation tests MUST be in the same directory due to the use of shared resources (for example,
110+
the local Complement server always binds to `:8448` which is a problem if 2 fed tests want to do that at the same time). This will be resolved in the future
111+
by the use of `.well-known` but at present this is how things stand.
112+
106113
### Should I always make a new blueprint for a test?
107114

108115
Probably not. Blueprints are costly, and they should only be made if there is a strong case for plenty of reuse among tests. In the same way that we don't always add fixtures to sytest, we should be sparing with adding blueprints.
@@ -140,6 +147,9 @@ t.Run("parallel", func(t *testing.T) {
140147
})
141148
```
142149

150+
Tests in a directory will run in parallel with tests in other directories by default. You can disable this by invoking `go test -p 1` which will
151+
force a parallelisation factor of 1 (no parallelisation).
152+
143153
### How should I do comments in the test?
144154

145155
Add long prose to the start of the function to outline what it is you're testing (and why if it is unclear). For example:
@@ -177,10 +187,6 @@ Use one of `t.Skipf(...)` or `t.SkipNow()`.
177187

178188
Error will fail the test but continue execution, where Fatal will fail the test and quit. Use Fatal when continuing to run the test will result in programming errors (e.g nil exceptions).
179189

180-
### Why do I get the error "Error response from daemon: Conflict. The container name "/complement_rooms_state_alice.hs1_1" is already in use by container "c2d1d90c6cff7b7de2678b56c702bd1ff76ca72b930e8f2ca32eef3f2514ff3b". You have to remove (or rename) that container to be able to reuse that name."?
181-
182-
The Docker daemon has a lag time between removing containers and them actually being removed. This means you cannot remove a container called 'foo' and immediately recreate it as 'foo'. To get around this, you need to use a different name. This probably means the namespace you have given the deployment is used by another test. Try changing it to something else e.g `Deploy(t, "rooms_state_2", b.BlueprintAlice.Name)`
183-
184190
### How do I run tests inside my IDE?
185191

186192
For VSCode, add to `settings.json`:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Complement is a black box integration testing framework for Matrix homeservers.
1010
You need to have Go and Docker installed, as well as `libolm3` and `libolm-dev`. Then:
1111

1212
```
13-
$ COMPLEMENT_BASE_IMAGE=some-matrix/homeserver-impl COMPLEMENT_BASE_IMAGE_ARGS='-foo bar -baz 1' go test -v ./tests
13+
$ COMPLEMENT_BASE_IMAGE=some-matrix/homeserver-impl COMPLEMENT_BASE_IMAGE_ARGS='-foo bar -baz 1' go test -v ./tests/...
1414
```
1515

1616
You can install `libolm3` on Debian using something like:
@@ -33,7 +33,7 @@ You can either use your own image, or one of the ones supplied in the [dockerfil
3333
A full list of config options can be found [in the config file](./internal/config/config.go). All normal Go test config
3434
options will work, so to just run 1 named test and include a timeout for the test run:
3535
```
36-
$ COMPLEMENT_BASE_IMAGE=complement-dendrite:latest go test -timeout 30s -run '^(TestOutboundFederationSend)$' -v ./tests
36+
$ COMPLEMENT_BASE_IMAGE=complement-dendrite:latest go test -timeout 30s -run '^(TestOutboundFederationSend)$' -v ./tests/...
3737
```
3838

3939
### Running against Dendrite
@@ -43,7 +43,7 @@ For instance, for Dendrite:
4343
# build a docker image for Dendrite...
4444
$ (cd dockerfiles && docker build -t complement-dendrite -f Dendrite.Dockerfile .)
4545
# ...and test it
46-
$ COMPLEMENT_BASE_IMAGE=complement-dendrite:latest go test -v ./tests
46+
$ COMPLEMENT_BASE_IMAGE=complement-dendrite:latest go test -v ./tests/...
4747
```
4848

4949
### Running against Synapse
@@ -61,7 +61,7 @@ To run Complement against a specific release of Synapse, set the
6161

6262
```sh
6363
docker build -t complement-synapse:v1.36.0 -f dockerfiles/Synapse.Dockerfile --build-arg=SYNAPSE_VERSION=v1.36.0 dockerfiles
64-
COMPLEMENT_BASE_IMAGE=complement-synapse:v1.36.0 go test ./tests
64+
COMPLEMENT_BASE_IMAGE=complement-synapse:v1.36.0 go test ./tests/...
6565
```
6666

6767
### Image requirements
@@ -95,7 +95,7 @@ being picked up by `go test`. For example, `apidoc_presence_test.go` has:
9595
```
9696
and all Dendrite tests run with `-tags="dendrite_blacklist"` to cause this file to be skipped. You can run tests with build tags like this:
9797
```
98-
COMPLEMENT_BASE_IMAGE=complement-synapse:latest go test -v -tags="synapse_blacklist,msc2403" ./tests
98+
COMPLEMENT_BASE_IMAGE=complement-synapse:latest go test -v -tags="synapse_blacklist,msc2403" ./tests/...
9999
```
100100
This runs Complement with a Synapse HS and ignores tests which Synapse doesn't implement, and includes tests for MSC2403.
101101

tests/account_change_password_pushers_test.go renamed to tests/csapi/account_change_password_pushers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build !dendrite_blacklist
22

3-
package tests
3+
package csapi_tests
44

55
import (
66
"testing"

tests/account_change_password_test.go renamed to tests/csapi/account_change_password_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tests
1+
package csapi_tests
22

33
import (
44
"io/ioutil"

tests/account_deactivate_test.go renamed to tests/csapi/account_deactivate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tests
1+
package csapi_tests
22

33
import (
44
"net/http"

tests/apidoc_device_management_test.go renamed to tests/csapi/apidoc_device_management_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tests
1+
package csapi_tests
22

33
import (
44
"testing"

tests/apidoc_login_test.go renamed to tests/csapi/apidoc_login_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tests
1+
package csapi_tests
22

33
import (
44
"encoding/json"

tests/apidoc_presence_test.go renamed to tests/csapi/apidoc_presence_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Rationale for being included in Dendrite's blacklist: https://github.com/matrix-org/complement/pull/104#discussion_r617646624
44

5-
package tests
5+
package csapi_tests
66

77
import (
88
"testing"

tests/apidoc_profile_avatar_url_test.go renamed to tests/csapi/apidoc_profile_avatar_url_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tests
1+
package csapi_tests
22

33
import (
44
"testing"

0 commit comments

Comments
 (0)