Skip to content

Commit

Permalink
Swap to COMPLEMENT_CRYPTO_TEST_CLIENT_MATRIX
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 3, 2023
1 parent 700fcee commit 7a5b511
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ TODO: consider checking in working builds so you can git clone and run. Git LFS

#### Environment Variables

- `COMPLEMENT_CRYPTO_TEST_CLIENTS` : "mixed", "rust" or "js"
Control which kinds of clients to make for tests. `rust` only tests rust clients. `js` only tests JS clients. `mixed` tests all 4 permutations.
- `COMPLEMENT_CRYPTO_TEST_CLIENT_MATRIX` : Comma separated clients to run. Default: `jj,jr,rj,rr`
Control which kinds of clients to make for tests. `r` creates Rust client. `j` creates JS clients. The default runs all permutations.


### Test hitlist
Expand Down
1 change: 0 additions & 1 deletion internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Client interface {
// Wait until an event with the given body is seen. Not all impls expose event IDs
// hence needing to use body as a proxy.
WaitUntilEventInRoom(t *testing.T, roomID, wantBody string) Waiter

Type() ClientType
}

Expand Down
68 changes: 30 additions & 38 deletions tests/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tests

import (
"fmt"
"os"
"strings"
"sync"
"testing"

Expand All @@ -11,27 +13,34 @@ import (
"github.com/matrix-org/complement/must"
)

const (
TestClientsMixed = "mixed"
TestClientsRustOnly = "rust"
TestClientsJSOnly = "js"
)

var (
ssDeployment *deploy.SlidingSyncDeployment
ssMutex *sync.Mutex
testClients = TestClientsMixed
ssDeployment *deploy.SlidingSyncDeployment
ssMutex *sync.Mutex
testClientMatrix = [][2]api.ClientType{} // set in TestMain
)

func TestMain(m *testing.M) {
ccTestClients := os.Getenv("COMPLEMENT_CRYPTO_TEST_CLIENTS")
switch ccTestClients {
case TestClientsRustOnly:
testClients = TestClientsRustOnly
case TestClientsJSOnly:
testClients = TestClientsJSOnly
default:
testClients = TestClientsMixed
ccTestClients := os.Getenv("COMPLEMENT_CRYPTO_TEST_CLIENT_MATRIX")
if ccTestClients == "" {
ccTestClients = "jj,jr,rj,rr"
}
segs := strings.Split(ccTestClients, ",")
for _, val := range segs { // e.g val == 'rj'
if len(val) != 2 {
panic("COMPLEMENT_CRYPTO_TEST_CLIENT_MATRIX bad value: " + val)
}
testCase := [2]api.ClientType{}
for i, ch := range val {
switch ch {
case 'r':
testCase[i] = api.ClientTypeRust
case 'j':
testCase[i] = api.ClientTypeJS
default:
panic("COMPLEMENT_CRYPTO_TEST_CLIENT_MATRIX bad value: " + val)
}
}
testClientMatrix = append(testClientMatrix, testCase)
}
ssMutex = &sync.Mutex{}
defer func() { // always teardown even if panicking
Expand All @@ -56,27 +65,10 @@ func Deploy(t *testing.T) *deploy.SlidingSyncDeployment {
}

func ClientTypeMatrix(t *testing.T, subTest func(tt *testing.T, a, b api.ClientType)) {
switch testClients {
case TestClientsJSOnly:
t.Run("JS|JS", func(t *testing.T) {
subTest(t, api.ClientTypeJS, api.ClientTypeJS)
})
case TestClientsRustOnly:
t.Run("Rust|Rust", func(t *testing.T) {
subTest(t, api.ClientTypeRust, api.ClientTypeRust)
})
case TestClientsMixed:
t.Run("Rust|Rust", func(t *testing.T) {
subTest(t, api.ClientTypeRust, api.ClientTypeRust)
})
t.Run("Rust|JS", func(t *testing.T) {
subTest(t, api.ClientTypeRust, api.ClientTypeJS)
})
t.Run("JS|Rust", func(t *testing.T) {
subTest(t, api.ClientTypeJS, api.ClientTypeRust)
})
t.Run("JS|JS", func(t *testing.T) {
subTest(t, api.ClientTypeJS, api.ClientTypeJS)
for _, tc := range testClientMatrix {
tc := tc
t.Run(fmt.Sprintf("%s|%s", tc[0], tc[1]), func(t *testing.T) {
subTest(t, tc[0], tc[1])
})
}
}
Expand Down

0 comments on commit 7a5b511

Please sign in to comment.