aboutsummaryrefslogtreecommitdiff
path: root/keyserver/internal
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2022-03-02 10:49:29 +0000
committerKegan Dougal <kegan@matrix.org>2022-03-02 10:49:36 +0000
commita4c918ee17d342e704aee738e4f0d5712b98eaa6 (patch)
treead852bf906c4556265a8e39b5c70a71618a82ee1 /keyserver/internal
parent00b3545b14ca5e6987be93cabafc51e771f8bcc7 (diff)
Fix data race in unit tests
Diffstat (limited to 'keyserver/internal')
-rw-r--r--keyserver/internal/device_list_update_test.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/keyserver/internal/device_list_update_test.go b/keyserver/internal/device_list_update_test.go
index e8d1bfe8..59a66ec8 100644
--- a/keyserver/internal/device_list_update_test.go
+++ b/keyserver/internal/device_list_update_test.go
@@ -87,6 +87,12 @@ func (d *mockDeviceListUpdaterDatabase) MarkDeviceListStale(ctx context.Context,
return nil
}
+func (d *mockDeviceListUpdaterDatabase) isStale(userID string) bool {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+ return d.staleUsers[userID]
+}
+
// StoreRemoteDeviceKeys persists the given keys. Keys with the same user ID and device ID will be replaced. An empty KeyJSON removes the key
// for this (user, device). Does not modify the stream ID for keys.
func (d *mockDeviceListUpdaterDatabase) StoreRemoteDeviceKeys(ctx context.Context, keys []api.DeviceMessage, clear []string) error {
@@ -169,7 +175,7 @@ func TestUpdateHavePrevID(t *testing.T) {
if !reflect.DeepEqual(db.storedKeys, []api.DeviceMessage{want}) {
t.Errorf("DB didn't store correct event, got %v want %v", db.storedKeys, want)
}
- if db.staleUsers[event.UserID] {
+ if db.isStale(event.UserID) {
t.Errorf("%s incorrectly marked as stale", event.UserID)
}
}
@@ -243,7 +249,7 @@ func TestUpdateNoPrevID(t *testing.T) {
},
}
// Now we should have a fresh list and the keys and emitted something
- if db.staleUsers[event.UserID] {
+ if db.isStale(event.UserID) {
t.Errorf("%s still marked as stale", event.UserID)
}
if !reflect.DeepEqual(producer.events, []api.DeviceMessage{want}) {
@@ -304,7 +310,7 @@ func TestDebounce(t *testing.T) {
}
// user should be marked as stale
- if !db.staleUsers[userID] {
+ if !db.isStale(userID) {
t.Errorf("user %s not marked as stale", userID)
}
// now send the response over federation
@@ -330,7 +336,7 @@ func TestDebounce(t *testing.T) {
wg.Wait()
// user is no longer stale now
- if db.staleUsers[userID] {
+ if db.isStale(userID) {
t.Errorf("user %s is marked as stale", userID)
}
}