Skip to content

Commit

Permalink
Merge pull request #153 from Hywan/fix-rust-sdk-new-cross-process-sto…
Browse files Browse the repository at this point in the history
…re-locks-api

fix(rust): Migrate to the new API
  • Loading branch information
Hywan authored Nov 12, 2024
2 parents f34c588 + a922c27 commit fb75e58
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func SetupLogs(prefix string) {
var zero uint32

const (
OptionEnableCrossProcessRefreshLockProcessName = "EnableCrossProcessRefreshLockProcessName"
CrossProcessStoreLocksHolderName = "CrossProcessStoreLocksHolderName"
)

// magic value for EnableCrossProcessRefreshLockProcessName which configures the FFI client
Expand Down Expand Up @@ -76,16 +76,16 @@ func NewRustClient(t ct.TestLike, opts api.ClientCreationOpts) (api.Client, erro
t.Logf("NewRustClient[%s][%s] creating...", opts.UserID, opts.DeviceID)
matrix_sdk_ffi.LogEvent("rust.go", &zero, matrix_sdk_ffi.LogLevelInfo, t.Name(), fmt.Sprintf("NewRustClient[%s][%s] creating...", opts.UserID, opts.DeviceID))
slidingSyncVersion := matrix_sdk_ffi.SlidingSyncVersionBuilderNative{}
clientSessionDelegate := NewMemoryClientSessionDelegate()
ab := matrix_sdk_ffi.NewClientBuilder().
HomeserverUrl(opts.BaseURL).
SlidingSyncVersionBuilder(slidingSyncVersion).
AutoEnableCrossSigning(true)
var clientSessionDelegate matrix_sdk_ffi.ClientSessionDelegate
xprocessName := opts.GetExtraOption(OptionEnableCrossProcessRefreshLockProcessName, "").(string)
AutoEnableCrossSigning(true).
SetSessionDelegate(clientSessionDelegate)
xprocessName := opts.GetExtraOption(CrossProcessStoreLocksHolderName, "").(string)
if xprocessName != "" {
t.Logf("enabling cross process refresh lock with proc name=%s", xprocessName)
clientSessionDelegate = NewMemoryClientSessionDelegate()
ab = ab.EnableCrossProcessRefreshLock(xprocessName, clientSessionDelegate)
t.Logf("setting cross process store locks holder name=%s", xprocessName)
ab = ab.CrossProcessStoreLocksHolderName(xprocessName)
}
// @alice:hs1, FOOBAR => alice_hs1_FOOBAR
username := strings.Replace(opts.UserID[1:], ":", "_", -1) + "_" + opts.DeviceID
Expand Down Expand Up @@ -345,9 +345,9 @@ 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()
xprocessName := c.opts.GetExtraOption(OptionEnableCrossProcessRefreshLockProcessName, "").(string)
xprocessName := c.opts.GetExtraOption(CrossProcessStoreLocksHolderName, "").(string)
if xprocessName != "" {
sb2 := sb.WithCrossProcessLock(&xprocessName)
sb2 := sb.WithCrossProcessLock()
sb.Destroy()
sb = sb2
}
Expand Down
38 changes: 19 additions & 19 deletions tests/rust/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func testNSEReceive(t *testing.T, numMsgsBefore, numMsgsAfter int) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand All @@ -88,7 +88,7 @@ func testNSEReceive(t *testing.T, numMsgsBefore, numMsgsAfter int) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: rust.ProcessNameNSE,
rust.CrossProcessStoreLocksHolderName: rust.ProcessNameNSE,
},
AccessToken: accessToken,
},
Expand All @@ -110,7 +110,7 @@ func TestNSEReceiveForNonPreKeyMessage(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand All @@ -137,7 +137,7 @@ func TestNSEReceiveForNonPreKeyMessage(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: rust.ProcessNameNSE,
rust.CrossProcessStoreLocksHolderName: rust.ProcessNameNSE,
},
AccessToken: accessToken,
},
Expand All @@ -164,7 +164,7 @@ func TestMultiprocessNSE(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestMultiprocessNSE(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
AccessToken: accessToken,
},
Expand All @@ -222,7 +222,7 @@ func TestMultiprocessNSE(t *testing.T) {
PersistentStorage: true,
AccessToken: accessToken,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
}) // this should login already as we provided an access token
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestMultiprocessNSE(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: rust.ProcessNameNSE,
rust.CrossProcessStoreLocksHolderName: rust.ProcessNameNSE,
},
AccessToken: accessToken,
},
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestMultiprocessNSE(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand All @@ -324,7 +324,7 @@ func TestMultiprocessNSEBackupKeyMacError(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestMultiprocessNSEBackupKeyMacError(t *testing.T) {
PersistentStorage: true,
AccessToken: accessToken,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
}) // this should login already as we provided an access token
Expand All @@ -377,7 +377,7 @@ func TestMultiprocessNSEBackupKeyMacError(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: rust.ProcessNameNSE,
rust.CrossProcessStoreLocksHolderName: rust.ProcessNameNSE,
},
AccessToken: accessToken,
},
Expand Down Expand Up @@ -419,7 +419,7 @@ func TestMultiprocessNSEBackupKeyMacError(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand All @@ -443,7 +443,7 @@ func TestMultiprocessNSEOlmSessionWedge(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand Down Expand Up @@ -478,7 +478,7 @@ func TestMultiprocessNSEOlmSessionWedge(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
AccessToken: accessToken,
},
Expand All @@ -503,7 +503,7 @@ func TestMultiprocessNSEOlmSessionWedge(t *testing.T) {
PersistentStorage: true,
AccessToken: accessToken,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: rust.ProcessNameNSE,
rust.CrossProcessStoreLocksHolderName: rust.ProcessNameNSE,
},
},
}) // this should login already as we provided an access token
Expand Down Expand Up @@ -639,7 +639,7 @@ func TestMultiprocessInitialE2EESyncDoesntDropDeviceListUpdates(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
},
})
Expand Down Expand Up @@ -673,7 +673,7 @@ func TestMultiprocessInitialE2EESyncDoesntDropDeviceListUpdates(t *testing.T) {
Opts: api.ClientCreationOpts{
PersistentStorage: true,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: "main",
rust.CrossProcessStoreLocksHolderName: "main",
},
AccessToken: accessToken,
},
Expand All @@ -687,7 +687,7 @@ func TestMultiprocessInitialE2EESyncDoesntDropDeviceListUpdates(t *testing.T) {
PersistentStorage: true,
AccessToken: accessToken,
ExtraOpts: map[string]any{
rust.OptionEnableCrossProcessRefreshLockProcessName: rust.ProcessNameNSE,
rust.CrossProcessStoreLocksHolderName: rust.ProcessNameNSE,
},
},
}) // this should login already as we provided an access token
Expand Down

0 comments on commit fb75e58

Please sign in to comment.