Skip to content

Commit

Permalink
Merge pull request #52 from matrix-org/kegan/multiprocess-nse
Browse files Browse the repository at this point in the history
Add tests for wedged olm sessions and corrupted backups
  • Loading branch information
kegsay authored May 15, 2024
2 parents 4eb67d2 + cd57c44 commit 17c6375
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 11 deletions.
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

0 comments on commit 17c6375

Please sign in to comment.