-
Notifications
You must be signed in to change notification settings - Fork 57
Move CSAPI only tests to tests/csapi #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c54eaf6
Move CSAPI only tests to tests/csapi
kegsay d955be3
go test ./...
kegsay 200c468
Update github actions
kegsay 8bcccb7
Track number of cpu cores on GH actions
kegsay 80d3fd7
Linting
kegsay 1f6d706
Force 2 parallel executions
kegsay 19f9a22
No more lscpu
kegsay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.