Skip to content

Commit

Permalink
More safeguards when errors occur
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Feb 12, 2024
1 parent 66a31aa commit 212255a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 17 additions & 12 deletions internal/api/rust/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,25 @@ func (c *RustClient) MustBackupKeys(t ct.TestLike) (recoveryKey string) {
genericListener := newGenericStateListener[matrix_sdk_ffi.EnableRecoveryProgress]()
var listener matrix_sdk_ffi.EnableRecoveryProgressListener = genericListener
recoveryKey, err := c.FFIClient.Encryption().EnableRecovery(true, listener)
for s := range genericListener.ch {
switch x := s.(type) {
case matrix_sdk_ffi.EnableRecoveryProgressCreatingBackup:
t.Logf("MustBackupKeys: state=CreatingBackup")
case matrix_sdk_ffi.EnableRecoveryProgressBackingUp:
t.Logf("MustBackupKeys: state=BackingUp %v/%v", x.BackedUpCount, x.TotalCount)
case matrix_sdk_ffi.EnableRecoveryProgressCreatingRecoveryKey:
t.Logf("MustBackupKeys: state=CreatingRecoveryKey")
case matrix_sdk_ffi.EnableRecoveryProgressDone:
t.Logf("MustBackupKeys: state=Done")
genericListener.Close() // break the loop
must.NotError(t, "Encryption.EnableRecovery", err)
for !genericListener.isClosed {
select {
case s := <-genericListener.ch:
switch x := s.(type) {
case matrix_sdk_ffi.EnableRecoveryProgressCreatingBackup:
t.Logf("MustBackupKeys: state=CreatingBackup")
case matrix_sdk_ffi.EnableRecoveryProgressBackingUp:
t.Logf("MustBackupKeys: state=BackingUp %v/%v", x.BackedUpCount, x.TotalCount)
case matrix_sdk_ffi.EnableRecoveryProgressCreatingRecoveryKey:
t.Logf("MustBackupKeys: state=CreatingRecoveryKey")
case matrix_sdk_ffi.EnableRecoveryProgressDone:
t.Logf("MustBackupKeys: state=Done")
genericListener.Close() // break the loop
}
case <-time.After(5 * time.Second):
ct.Fatalf(t, "timed out enabling backup keys")
}
}
must.NotError(t, "Encryption.EnableRecovery", err)
return recoveryKey
}

Expand Down
6 changes: 5 additions & 1 deletion tests/state_synchronisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func testSigkillBeforeKeysUploadResponseJS(t *testing.T, clientType api.ClientTy
}
// destroy the client
mu.Lock()
terminateClient()
if terminateClient != nil {
terminateClient()
} else {
ct.Errorf(t, "terminateClient is nil. Did WithMITMOptions lock?")
}
mu.Unlock()
})
defer close()
Expand Down

0 comments on commit 212255a

Please sign in to comment.