Skip to content

Commit

Permalink
rust: always use persistence in clients
Browse files Browse the repository at this point in the history
Previously we would only use persistence when the test strictly needed
it e.g to test what happens between restarts. It's preferable to always
run with persistence because:
 - it more accurately models real Element X clients e.g performance
   characteristics, runtime code.
 - any bugs in the DB layer are then also bugs in the client. Using
   the memory store has proven [error prone](matrix-org/matrix-rust-sdk#3668)
   and fixing these bugs don't improve the stability of EX at all.

`ClientCreationOpts` will still have the `Persistence` flag though,
as it remains useful to know when a test _needs_ persistence vs when
it does not. In the future, we may clean up locally stored files
during test runtime, and this flag would allow us to know whether it
is safe to delete the files or not.
  • Loading branch information
kegsay committed Jul 9, 2024
1 parent 8a00917 commit 957b9fc
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,21 @@ func NewRustClient(t ct.TestLike, opts api.ClientCreationOpts) (api.Client, erro
clientSessionDelegate = NewMemoryClientSessionDelegate()
ab = ab.EnableCrossProcessRefreshLock(opts.EnableCrossProcessRefreshLockProcessName, clientSessionDelegate)
}
var username string
if opts.PersistentStorage {
// @alice:hs1, FOOBAR => alice_hs1_FOOBAR
username = strings.Replace(opts.UserID[1:], ":", "_", -1) + "_" + opts.DeviceID
ab = ab.SessionPath("rust_storage/" + username).Username(username)
}
// @alice:hs1, FOOBAR => alice_hs1_FOOBAR
username := strings.Replace(opts.UserID[1:], ":", "_", -1) + "_" + opts.DeviceID
ab = ab.SessionPath("rust_storage/" + username).Username(username)
client, err := ab.Build()
if err != nil {
return nil, fmt.Errorf("ClientBuilder.Build failed: %s", err)
}
c := &RustClient{
userID: opts.UserID,
FFIClient: client,
roomsListener: NewRoomsListener(),
rooms: make(map[string]*RustRoomInfo),
roomsMu: &sync.RWMutex{},
opts: opts,
}
if opts.PersistentStorage {
c.persistentStoragePath = "./rust_storage/" + username
userID: opts.UserID,
FFIClient: client,
roomsListener: NewRoomsListener(),
rooms: make(map[string]*RustRoomInfo),
roomsMu: &sync.RWMutex{},
opts: opts,
persistentStoragePath: "./rust_storage/" + username,
}
if opts.AccessToken != "" { // restore the session
session := matrix_sdk_ffi.Session{
Expand Down

0 comments on commit 957b9fc

Please sign in to comment.