-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
20 changed files
with
161 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/account_change_password_pushers_test.go → ...i/account_change_password_pushers_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// +build !dendrite_blacklist | ||
|
||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/account_change_password_test.go → tests/csapi/account_change_password_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"io/ioutil" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/account_deactivate_test.go → tests/csapi/account_deactivate_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"net/http" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_device_management_test.go → tests/csapi/apidoc_device_management_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/apidoc_profile_avatar_url_test.go → ...s/csapi/apidoc_profile_avatar_url_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_profile_displayname_test.go → .../csapi/apidoc_profile_displayname_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_register_test.go → tests/csapi/apidoc_register_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"encoding/json" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_request_encoding_test.go → tests/csapi/apidoc_request_encoding_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_room_create_test.go → tests/csapi/apidoc_room_create_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_room_state_test.go → tests/csapi/apidoc_room_state_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"net/url" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/apidoc_version_test.go → tests/csapi/apidoc_version_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package csapi_tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/matrix-org/complement/internal/b" | ||
"github.com/matrix-org/complement/internal/config" | ||
"github.com/matrix-org/complement/internal/docker" | ||
"github.com/matrix-org/complement/internal/federation" | ||
) | ||
|
||
var namespaceCounter uint64 | ||
|
||
// persist the complement builder which is set when the tests start via TestMain | ||
var complementBuilder *docker.Builder | ||
|
||
// TestMain is the main entry point for Complement. | ||
// | ||
// It will clean up any old containers/images/networks from the previous run, then run the tests, then clean up | ||
// again. No blueprints are made at this point as they are lazily made on demand. | ||
func TestMain(m *testing.M) { | ||
cfg := config.NewConfigFromEnvVars() | ||
cfg.PackageNamespace = "csapi" | ||
log.Printf("config: %+v", cfg) | ||
builder, err := docker.NewBuilder(cfg) | ||
if err != nil { | ||
fmt.Printf("Error: %s", err) | ||
os.Exit(1) | ||
} | ||
complementBuilder = builder | ||
// remove any old images/containers/networks in case we died horribly before | ||
builder.Cleanup() | ||
|
||
if os.Getenv("COMPLEMENT_CA") == "true" { | ||
log.Printf("Running with Complement CA") | ||
// make sure CA certs are generated | ||
_, _, err = federation.GetOrCreateCaCert() | ||
if err != nil { | ||
fmt.Printf("Error: %s", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// we use GMSL which uses logrus by default. We don't want those logs in our test output unless they are Serious. | ||
logrus.SetLevel(logrus.ErrorLevel) | ||
|
||
exitCode := m.Run() | ||
builder.Cleanup() | ||
os.Exit(exitCode) | ||
} | ||
|
||
// Deploy will deploy the given blueprint or terminate the test. | ||
// It will construct the blueprint if it doesn't already exist in the docker image cache. | ||
// This function is the main setup function for all tests as it provides a deployment with | ||
// which tests can interact with. | ||
func Deploy(t *testing.T, blueprint b.Blueprint) *docker.Deployment { | ||
t.Helper() | ||
timeStartBlueprint := time.Now() | ||
if complementBuilder == nil { | ||
t.Fatalf("complementBuilder not set, did you forget to call TestMain?") | ||
} | ||
if err := complementBuilder.ConstructBlueprintsIfNotExist([]b.Blueprint{blueprint}); err != nil { | ||
t.Fatalf("Deploy: Failed to construct blueprint: %s", err) | ||
} | ||
namespace := fmt.Sprintf("%d", atomic.AddUint64(&namespaceCounter, 1)) | ||
d, err := docker.NewDeployer(namespace, complementBuilder.Config) | ||
if err != nil { | ||
t.Fatalf("Deploy: NewDeployer returned error %s", err) | ||
} | ||
timeStartDeploy := time.Now() | ||
dep, err := d.Deploy(context.Background(), blueprint.Name) | ||
if err != nil { | ||
t.Fatalf("Deploy: Deploy returned error %s", err) | ||
} | ||
t.Logf("Deploy times: %v blueprints, %v containers", timeStartDeploy.Sub(timeStartBlueprint), time.Since(timeStartDeploy)) | ||
return dep | ||
} | ||
|
||
// nolint:unused | ||
type Waiter struct { | ||
mu sync.Mutex | ||
ch chan bool | ||
closed bool | ||
} | ||
|
||
// NewWaiter returns a generic struct which can be waited on until `Waiter.Finish` is called. | ||
// A Waiter is similar to a `sync.WaitGroup` of size 1, but without the ability to underflow and | ||
// with built-in timeouts. | ||
// nolint:unused | ||
func NewWaiter() *Waiter { | ||
return &Waiter{ | ||
ch: make(chan bool), | ||
mu: sync.Mutex{}, | ||
} | ||
} | ||
|
||
// Wait blocks until Finish() is called or until the timeout is reached. | ||
// If the timeout is reached, the test is failed. | ||
func (w *Waiter) Wait(t *testing.T, timeout time.Duration) { | ||
t.Helper() | ||
select { | ||
case <-w.ch: | ||
return | ||
case <-time.After(timeout): | ||
t.Fatalf("Wait: timed out after %f seconds.", timeout.Seconds()) | ||
} | ||
} | ||
|
||
// Finish will cause all goroutines waiting via Wait to stop waiting and return. | ||
// Once this function has been called, subsequent calls to Wait will return immediately. | ||
// To begin waiting again, make a new Waiter. | ||
func (w *Waiter) Finish() { | ||
w.mu.Lock() | ||
defer w.mu.Unlock() | ||
if w.closed { | ||
return | ||
} | ||
w.closed = true | ||
close(w.ch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package tests | ||
package csapi_tests | ||
|
||
import ( | ||
"encoding/json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters