Skip to content

Commit 17c6375

Browse files
authored
Merge pull request #52 from matrix-org/kegan/multiprocess-nse
Add tests for wedged olm sessions and corrupted backups
2 parents 4eb67d2 + cd57c44 commit 17c6375

File tree

5 files changed

+404
-11
lines changed

5 files changed

+404
-11
lines changed

internal/api/rust/rust.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func SetupLogs(prefix string) {
3030
// log new files
3131
matrix_sdk_ffi.SetupTracing(matrix_sdk_ffi.TracingConfiguration{
3232
WriteToStdoutOrSystem: false,
33-
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",
33+
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",
3434
WriteToFiles: &matrix_sdk_ffi.TracingFileConfiguration{
3535
Path: "./logs",
3636
FilePrefix: prefix,
@@ -253,6 +253,11 @@ func (c *RustClient) StartSyncing(t ct.TestLike) (stopSyncing func(), err error)
253253
// > thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'
254254
// where the stack trace doesn't hit any test code, but does start at a `free_` function.
255255
sb := c.FFIClient.SyncService()
256+
if c.opts.EnableCrossProcessRefreshLockProcessName != "" {
257+
sb2 := sb.WithCrossProcessLock(&c.opts.EnableCrossProcessRefreshLockProcessName)
258+
sb.Destroy()
259+
sb = sb2
260+
}
256261
defer sb.Destroy()
257262
syncService, err := sb.Finish()
258263
if err != nil {

internal/deploy/rpc_client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ import (
1717

1818
// RPCLanguageBindings implements api.LanguageBindings and instead issues RPC calls to a remote server.
1919
type RPCLanguageBindings struct {
20-
binaryPath string
21-
clientType api.ClientTypeLang
20+
binaryPath string
21+
clientType api.ClientTypeLang
22+
contextPrefix string
2223
}
2324

24-
func NewRPCLanguageBindings(rpcBinaryPath string, clientType api.ClientTypeLang) (*RPCLanguageBindings, error) {
25+
func NewRPCLanguageBindings(rpcBinaryPath string, clientType api.ClientTypeLang, contextPrefix string) (*RPCLanguageBindings, error) {
2526
return &RPCLanguageBindings{
26-
binaryPath: rpcBinaryPath,
27-
clientType: clientType,
27+
binaryPath: rpcBinaryPath,
28+
clientType: clientType,
29+
contextPrefix: contextPrefix,
2830
}, nil
2931
}
3032

@@ -46,7 +48,7 @@ func (r *RPCLanguageBindings) PostTestRun(contextID string) {
4648
// - IPC via stdout fails (used to extract the random high numbered port)
4749
// - the client cannot talk to the rpc server
4850
func (r *RPCLanguageBindings) MustCreateClient(t ct.TestLike, cfg api.ClientCreationOpts) api.Client {
49-
contextID := fmt.Sprintf("%s_%s", strings.Replace(cfg.UserID[1:], ":", "_", -1), cfg.DeviceID)
51+
contextID := fmt.Sprintf("%s%s_%s", r.contextPrefix, strings.Replace(cfg.UserID[1:], ":", "_", -1), cfg.DeviceID)
5052
// security: check it is a file not a random bash script...
5153
if _, err := os.Stat(r.binaryPath); err != nil {
5254
ct.Fatalf(t, "%s: RPC binary at %s does not exist or cannot be executed/read: %s", contextID, r.binaryPath, err)

internal/tests/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestMain(m *testing.M) {
6060
rpcBinary := os.Getenv("COMPLEMENT_CRYPTO_RPC_BINARY")
6161
if rpcBinary != "" {
6262
clientFactories = append(clientFactories, func(t *testing.T, cfg api.ClientCreationOpts) api.Client {
63-
remoteBindings, err := deploy.NewRPCLanguageBindings(rpcBinary, api.ClientTypeRust)
63+
remoteBindings, err := deploy.NewRPCLanguageBindings(rpcBinary, api.ClientTypeRust, "")
6464
if err != nil {
6565
log.Fatal(err)
6666
}

tests/main_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"sync"
8+
"sync/atomic"
89
"testing"
910

1011
"github.com/matrix-org/complement"
@@ -131,10 +132,19 @@ func WithCrossProcessLock(processName string) func(*api.ClientCreationOpts) {
131132
}
132133
}
133134

135+
// WithAccessToken is an option which can be provided to MustCreateClient which will configure an access token for the client.
136+
// No-ops on non-rust clients, for now. In theory this option should be generic to configure an already logged in client. TODO
137+
func WithAccessToken(accessToken string) func(*api.ClientCreationOpts) {
138+
return func(o *api.ClientCreationOpts) {
139+
o.AccessToken = accessToken
140+
}
141+
}
142+
134143
// TestContext provides a consistent set of variables which most tests will need access to.
135144
type TestContext struct {
136145
Deployment *deploy.SlidingSyncDeployment
137146
RPCBinaryPath string
147+
RPCInstance atomic.Int32
138148
// Alice is defined if at least 1 clientType is provided to CreateTestContext.
139149
Alice *client.CSAPI
140150
AliceClientType api.ClientType
@@ -205,7 +215,8 @@ func (c *TestContext) MustCreateMultiprocessClient(t *testing.T, lang api.Client
205215
t.Skipf("RPC binary path not provided, skipping multiprocess test. To run this test, set COMPLEMENT_CRYPTO_RPC_BINARY")
206216
return nil
207217
}
208-
remoteBindings, err := deploy.NewRPCLanguageBindings(c.RPCBinaryPath, lang)
218+
ctxPrefix := fmt.Sprintf("%d", c.RPCInstance.Add(1))
219+
remoteBindings, err := deploy.NewRPCLanguageBindings(c.RPCBinaryPath, lang, ctxPrefix)
209220
if err != nil {
210221
t.Fatalf("Failed to create new RPC language bindings: %s", err)
211222
}

0 commit comments

Comments
 (0)