Skip to content
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

Add tests for wedged olm sessions and corrupted backups #52

Merged
merged 12 commits into from
May 15, 2024
7 changes: 6 additions & 1 deletion internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func SetupLogs(prefix string) {
// log new files
matrix_sdk_ffi.SetupTracing(matrix_sdk_ffi.TracingConfiguration{
WriteToStdoutOrSystem: false,
Filter: "debug,hyper=warn,log=warn,eyeball=warn", //,matrix_sdk_ffi=trace,matrix_sdk=trace,matrix_sdk_crypto=trace,matrix_sdk_base=trace,matrix_sdk_ui=trace",
Filter: "debug,hyper=warn,log=warn,eyeball=warn,matrix_sdk_common=trace", //,matrix_sdk_ffi=trace,matrix_sdk=trace,matrix_sdk_crypto=trace,matrix_sdk_base=trace,matrix_sdk_ui=trace",
WriteToFiles: &matrix_sdk_ffi.TracingFileConfiguration{
Path: "./logs",
FilePrefix: prefix,
Expand Down Expand Up @@ -253,6 +253,11 @@ func (c *RustClient) StartSyncing(t ct.TestLike) (stopSyncing func(), err error)
// > thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'
// where the stack trace doesn't hit any test code, but does start at a `free_` function.
sb := c.FFIClient.SyncService()
if c.opts.EnableCrossProcessRefreshLockProcessName != "" {
sb2 := sb.WithCrossProcessLock(&c.opts.EnableCrossProcessRefreshLockProcessName)
sb.Destroy()
sb = sb2
}
defer sb.Destroy()
syncService, err := sb.Finish()
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions internal/deploy/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import (

// RPCLanguageBindings implements api.LanguageBindings and instead issues RPC calls to a remote server.
type RPCLanguageBindings struct {
binaryPath string
clientType api.ClientTypeLang
binaryPath string
clientType api.ClientTypeLang
contextPrefix string
}

func NewRPCLanguageBindings(rpcBinaryPath string, clientType api.ClientTypeLang) (*RPCLanguageBindings, error) {
func NewRPCLanguageBindings(rpcBinaryPath string, clientType api.ClientTypeLang, contextPrefix string) (*RPCLanguageBindings, error) {
return &RPCLanguageBindings{
binaryPath: rpcBinaryPath,
clientType: clientType,
binaryPath: rpcBinaryPath,
clientType: clientType,
contextPrefix: contextPrefix,
}, nil
}

Expand All @@ -46,7 +48,7 @@ func (r *RPCLanguageBindings) PostTestRun(contextID string) {
// - IPC via stdout fails (used to extract the random high numbered port)
// - the client cannot talk to the rpc server
func (r *RPCLanguageBindings) MustCreateClient(t ct.TestLike, cfg api.ClientCreationOpts) api.Client {
contextID := fmt.Sprintf("%s_%s", strings.Replace(cfg.UserID[1:], ":", "_", -1), cfg.DeviceID)
contextID := fmt.Sprintf("%s%s_%s", r.contextPrefix, strings.Replace(cfg.UserID[1:], ":", "_", -1), cfg.DeviceID)
// security: check it is a file not a random bash script...
if _, err := os.Stat(r.binaryPath); err != nil {
ct.Fatalf(t, "%s: RPC binary at %s does not exist or cannot be executed/read: %s", contextID, r.binaryPath, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/tests/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestMain(m *testing.M) {
rpcBinary := os.Getenv("COMPLEMENT_CRYPTO_RPC_BINARY")
if rpcBinary != "" {
clientFactories = append(clientFactories, func(t *testing.T, cfg api.ClientCreationOpts) api.Client {
remoteBindings, err := deploy.NewRPCLanguageBindings(rpcBinary, api.ClientTypeRust)
remoteBindings, err := deploy.NewRPCLanguageBindings(rpcBinary, api.ClientTypeRust, "")
if err != nil {
log.Fatal(err)
}
Expand Down
13 changes: 12 additions & 1 deletion tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"sync"
"sync/atomic"
"testing"

"github.com/matrix-org/complement"
Expand Down Expand Up @@ -131,10 +132,19 @@ func WithCrossProcessLock(processName string) func(*api.ClientCreationOpts) {
}
}

// WithAccessToken is an option which can be provided to MustCreateClient which will configure an access token for the client.
// No-ops on non-rust clients, for now. In theory this option should be generic to configure an already logged in client. TODO
func WithAccessToken(accessToken string) func(*api.ClientCreationOpts) {
return func(o *api.ClientCreationOpts) {
o.AccessToken = accessToken
}
}

// TestContext provides a consistent set of variables which most tests will need access to.
type TestContext struct {
Deployment *deploy.SlidingSyncDeployment
RPCBinaryPath string
RPCInstance atomic.Int32
// Alice is defined if at least 1 clientType is provided to CreateTestContext.
Alice *client.CSAPI
AliceClientType api.ClientType
Expand Down Expand Up @@ -205,7 +215,8 @@ func (c *TestContext) MustCreateMultiprocessClient(t *testing.T, lang api.Client
t.Skipf("RPC binary path not provided, skipping multiprocess test. To run this test, set COMPLEMENT_CRYPTO_RPC_BINARY")
return nil
}
remoteBindings, err := deploy.NewRPCLanguageBindings(c.RPCBinaryPath, lang)
ctxPrefix := fmt.Sprintf("%d", c.RPCInstance.Add(1))
remoteBindings, err := deploy.NewRPCLanguageBindings(c.RPCBinaryPath, lang, ctxPrefix)
if err != nil {
t.Fatalf("Failed to create new RPC language bindings: %s", err)
}
Expand Down
Loading
Loading