From 9982ab24ee362b4800ec560efcfbb1cdf089cafe Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 15 May 2023 19:11:48 +0100 Subject: [PATCH] Use different device names for each test --- tests-integration/bench_test.go | 2 +- tests-integration/connection_test.go | 22 +++++++++--------- tests-integration/extensions_test.go | 8 +++---- tests-integration/invite_test.go | 2 +- tests-integration/lists_test.go | 2 +- tests-integration/metrics_test.go | 8 +++---- tests-integration/notifications_test.go | 2 +- tests-integration/poller_test.go | 6 ++--- tests-integration/rig_test.go | 2 +- tests-integration/room_names_test.go | 2 +- tests-integration/room_subscriptions_test.go | 2 +- tests-integration/slow_get_all_rooms_test.go | 2 +- tests-integration/timeline_test.go | 24 ++++++++++---------- tests-integration/token_management_test.go | 6 +++-- tests-integration/v3_test.go | 10 ++++---- 15 files changed, 52 insertions(+), 48 deletions(-) diff --git a/tests-integration/bench_test.go b/tests-integration/bench_test.go index 88eecdb1..59bfe93b 100644 --- a/tests-integration/bench_test.go +++ b/tests-integration/bench_test.go @@ -52,7 +52,7 @@ func benchNumV2Rooms(numRooms int, b *testing.B) { }...), } } - v2.addAccount(alice, aliceToken) + v2.addAccount(b, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), diff --git a/tests-integration/connection_test.go b/tests-integration/connection_test.go index 56211ecb..2bf3960f 100644 --- a/tests-integration/connection_test.go +++ b/tests-integration/connection_test.go @@ -27,7 +27,7 @@ func TestMultipleConnsAtStartup(t *testing.T) { defer v2.close() defer v3.close() roomID := "!a:localhost" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) var res *sync3.Response var wg sync.WaitGroup wg.Add(1) @@ -104,7 +104,7 @@ func TestOutstandingRequestsGetCancelled(t *testing.T) { // failing the test. roomA := "!a:localhost" // name is A, older timestamp roomB := "!b:localhost" // name is B, newer timestamp - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -209,7 +209,7 @@ func TestConnectionTimeoutNotReset(t *testing.T) { // used to reset the timeout though, so we will check to make sure it doesn't. roomA := "!a:localhost" roomB := "!b:localhost" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -298,7 +298,7 @@ func TestTxnIDEcho(t *testing.T) { defer v3.close() roomID := "!a:localhost" txnID := "hi" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{}) res := v3.mustDoV3Request(t, aliceToken, sync3.Request{ @@ -350,7 +350,7 @@ func TestTxnIDResponseBuffering(t *testing.T) { roomA := "!a:localhost" roomB := "!b:localhost" roomC := "!c:localhost" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -458,8 +458,8 @@ func TestEnsurePollingDoesntQueue(t *testing.T) { defer v3.close() roomA := "!a:localhost" roomB := "!b:localhost" - v2.addAccount(alice, aliceToken) - v2.addAccount(bob, bobToken) + v2.addAccount(t, alice, aliceToken) + v2.addAccount(t, bob, bobToken) v2.queueResponse(bob, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -539,7 +539,7 @@ func TestEnsurePollingDoesntQueue(t *testing.T) { func TestSessionExpiry(t *testing.T) { pqString := testutils.PrepareDBConnectionString() v2 := runTestV2Server(t) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v3 := runTestServer(t, v2, pqString) roomID := "!doesnt:matter" res1 := v3.mustDoV3Request(t, aliceToken, sync3.Request{ @@ -568,7 +568,7 @@ func TestSessionExpiryOnBufferFill(t *testing.T) { maxPendingEventUpdates := 3 pqString := testutils.PrepareDBConnectionString() v2 := runTestV2Server(t) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -627,7 +627,7 @@ func TestSessionExpiryOnBufferFill(t *testing.T) { func TestExpiredAccessToken(t *testing.T) { pqString := testutils.PrepareDBConnectionString() v2 := runTestV2Server(t) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v3 := runTestServer(t, v2, pqString) roomID := "!doesnt:matter" res := v3.mustDoV3Request(t, aliceToken, sync3.Request{ @@ -651,7 +651,7 @@ func TestExpiredAccessToken(t *testing.T) { func TestExpiredAccessTokenMultipleConns(t *testing.T) { pqString := testutils.PrepareDBConnectionString() v2 := runTestV2Server(t) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v3 := runTestServer(t, v2, pqString) roomID := "!doesnt:matter" resA := v3.mustDoV3Request(t, aliceToken, sync3.Request{ diff --git a/tests-integration/extensions_test.go b/tests-integration/extensions_test.go index 10237606..c9a9934a 100644 --- a/tests-integration/extensions_test.go +++ b/tests-integration/extensions_test.go @@ -29,7 +29,7 @@ func TestExtensionE2EE(t *testing.T) { "signed_curve25519": 100, } fallbackKeyTypes := []string{"signed_curve25519"} - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ DeviceListsOTKCount: otkCounts, DeviceUnusedFallbackKeyTypes: fallbackKeyTypes, @@ -211,7 +211,7 @@ func TestExtensionToDevice(t *testing.T) { defer v3.close() alice := "@TestExtensionToDevice_alice:localhost" aliceToken := "ALICE_BEARER_TOKEN_TestExtensionToDevice" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) toDeviceMsgs := []json.RawMessage{ json.RawMessage(`{"sender":"alice","type":"something","content":{"foo":"1"}}`), json.RawMessage(`{"sender":"alice","type":"something","content":{"foo":"2"}}`), @@ -410,7 +410,7 @@ func TestExtensionAccountData(t *testing.T) { testutils.NewAccountData(t, "im-c", map[string]interface{}{"body": "yep c"}), testutils.NewAccountData(t, "im-also-c", map[string]interface{}{"body": "yep C"}), } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ AccountData: sync2.EventsResponse{ Events: globalAccountData, @@ -577,7 +577,7 @@ func TestExtensionLateEnable(t *testing.T) { defer v2.close() defer v3.close() - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ diff --git a/tests-integration/invite_test.go b/tests-integration/invite_test.go index a755bb0f..3d18e07b 100644 --- a/tests-integration/invite_test.go +++ b/tests-integration/invite_test.go @@ -27,7 +27,7 @@ func TestStuckInvites(t *testing.T) { "membership": "invite", })) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Invite: map[string]sync2.SyncV2InviteResponse{ diff --git a/tests-integration/lists_test.go b/tests-integration/lists_test.go index 7b130eaf..bab3b495 100644 --- a/tests-integration/lists_test.go +++ b/tests-integration/lists_test.go @@ -113,7 +113,7 @@ func TestUnreadCountMisordering(t *testing.T) { notifCount: &info.notifCount, }) } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(re...), diff --git a/tests-integration/metrics_test.go b/tests-integration/metrics_test.go index f332f9b9..1f6adf7d 100644 --- a/tests-integration/metrics_test.go +++ b/tests-integration/metrics_test.go @@ -70,7 +70,7 @@ func TestMetricsNumPollers(t *testing.T) { metrics := getMetrics(t, metricsServer) assertMetric(t, metrics, metricKey, "0") // start a poller - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -84,7 +84,7 @@ func TestMetricsNumPollers(t *testing.T) { metrics = getMetrics(t, metricsServer) assertMetric(t, metrics, metricKey, "1") // start another poller - v2.addAccount(bob, bobToken) + v2.addAccount(t, bob, bobToken) v2.queueResponse(bob, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -119,7 +119,7 @@ func TestMetricsNumConns(t *testing.T) { metrics := getMetrics(t, metricsServer) assertMetric(t, metrics, metricKey, "0") // start a poller - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -133,7 +133,7 @@ func TestMetricsNumConns(t *testing.T) { metrics = getMetrics(t, metricsServer) assertMetric(t, metrics, metricKey, "1") // start another poller - v2.addAccount(bob, bobToken) + v2.addAccount(t, bob, bobToken) v2.queueResponse(bob, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ diff --git a/tests-integration/notifications_test.go b/tests-integration/notifications_test.go index 4ff64582..c2efe3c9 100644 --- a/tests-integration/notifications_test.go +++ b/tests-integration/notifications_test.go @@ -45,7 +45,7 @@ func TestNotificationsOnTop(t *testing.T) { }...), }, } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), diff --git a/tests-integration/poller_test.go b/tests-integration/poller_test.go index 831533e6..ede09cdb 100644 --- a/tests-integration/poller_test.go +++ b/tests-integration/poller_test.go @@ -124,7 +124,7 @@ func TestPollerHandlesUnknownStateEventsOnIncrementalSync(t *testing.T) { v3 := runTestServer(t, v2, pqString) defer v2.close() defer v3.close() - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) const roomID = "!unimportant" v2.queueResponse(aliceToken, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ @@ -211,8 +211,8 @@ func TestPollerUpdatesRoomMemberTrackerOnGappySyncStateBlock(t *testing.T) { v3 := runTestServer(t, v2, pqString) defer v2.close() defer v3.close() - v2.addAccount(alice, aliceToken) - v2.addAccount(bob, bobToken) + v2.addAccount(t, alice, aliceToken) + v2.addAccount(t, bob, bobToken) const roomID = "!unimportant" t.Log("Alice and Bob's pollers initial sync. Both see the same state: that Alice and Bob share a room.") diff --git a/tests-integration/rig_test.go b/tests-integration/rig_test.go index 27a5ddea..6cddcb08 100644 --- a/tests-integration/rig_test.go +++ b/tests-integration/rig_test.go @@ -38,7 +38,7 @@ func (r *testRig) SetupV2RoomsForUser(t *testing.T, v2UserID string, f FlushEnum _, userExists := r.tokens[v2UserID] if !userExists { r.tokens[v2UserID] = "access_token_for_" + v2UserID - r.V2.addAccount(v2UserID, r.tokens[v2UserID]) + r.V2.addAccount(t, v2UserID, r.tokens[v2UserID]) } inviteRooms := make(map[string]sync2.SyncV2InviteResponse) joinRooms := make(map[string]sync2.SyncV2JoinResponse) diff --git a/tests-integration/room_names_test.go b/tests-integration/room_names_test.go index cf5baf8c..a98f1081 100644 --- a/tests-integration/room_names_test.go +++ b/tests-integration/room_names_test.go @@ -60,7 +60,7 @@ func TestRoomNames(t *testing.T) { }, }, } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), diff --git a/tests-integration/room_subscriptions_test.go b/tests-integration/room_subscriptions_test.go index 9ca6c885..99768f23 100644 --- a/tests-integration/room_subscriptions_test.go +++ b/tests-integration/room_subscriptions_test.go @@ -25,7 +25,7 @@ func TestRoomSubscriptionJoinRoomRace(t *testing.T) { events: createRoomState(t, alice, time.Now()), } // add the account and queue a dummy response so there is a poll loop and we can get requests serviced - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ diff --git a/tests-integration/slow_get_all_rooms_test.go b/tests-integration/slow_get_all_rooms_test.go index 1d4c2581..f5ea543f 100644 --- a/tests-integration/slow_get_all_rooms_test.go +++ b/tests-integration/slow_get_all_rooms_test.go @@ -52,7 +52,7 @@ func TestSlowGetAllRoomsInitial(t *testing.T) { m.MatchRoomTimelineMostRecent(numTimelineEventsPerRoom, allRooms[i].events), } } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), diff --git a/tests-integration/timeline_test.go b/tests-integration/timeline_test.go index 18d25d95..cb188d56 100644 --- a/tests-integration/timeline_test.go +++ b/tests-integration/timeline_test.go @@ -42,7 +42,7 @@ func TestTimelines(t *testing.T) { } } latestTimestamp := time.Now().Add(10 * time.Hour) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), @@ -124,7 +124,7 @@ func TestTimelinesLiveStream(t *testing.T) { latestTimestamp = ts.Add(10 * time.Second) } } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), @@ -256,7 +256,7 @@ func TestMultipleWindows(t *testing.T) { }...), } } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), @@ -338,7 +338,7 @@ func TestInitialFlag(t *testing.T) { defer v2.close() defer v3.close() roomID := "!a:localhost" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -401,7 +401,7 @@ func TestDuplicateEventsInTimeline(t *testing.T) { roomID := "!a:localhost" dupeEvent := testutils.NewStateEvent(t, "m.room.name", "", alice, map[string]interface{}{}) - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -459,7 +459,7 @@ func TestTimelineMiddleWindowZeroTimelineLimit(t *testing.T) { }...), } } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), @@ -555,7 +555,7 @@ func TestHistoryDoesntIncludeState(t *testing.T) { }, prevBatch: prevBatch, } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(room), @@ -595,8 +595,8 @@ func TestTimelineTxnID(t *testing.T) { testutils.NewJoinEvent(t, bob), ), } - v2.addAccount(alice, aliceToken) - v2.addAccount(bob, bobToken) + v2.addAccount(t, alice, aliceToken) + v2.addAccount(t, bob, bobToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(room), @@ -736,7 +736,7 @@ func TestPrevBatchInTimeline(t *testing.T) { defer v2.close() defer v3.close() roomID := "!a:localhost" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ @@ -845,7 +845,7 @@ func TestTrickling(t *testing.T) { }...), } } - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(allRooms...), @@ -1019,7 +1019,7 @@ func TestNumLiveBulk(t *testing.T) { defer v3.close() roomID := "!bulk:test" - v2.addAccount(alice, aliceToken) + v2.addAccount(t, alice, aliceToken) v2.queueResponse(alice, sync2.SyncResponse{ Rooms: sync2.SyncRoomsResponse{ Join: v2JoinTimeline(roomEvents{ diff --git a/tests-integration/token_management_test.go b/tests-integration/token_management_test.go index f13fc158..a2b0f726 100644 --- a/tests-integration/token_management_test.go +++ b/tests-integration/token_management_test.go @@ -18,11 +18,13 @@ func TestSyncWithNewTokenAfterOldExpires(t *testing.T) { pqString := testutils.PrepareDBConnectionString() v2 := runTestV2Server(t) v3 := runTestServer(t, v2, pqString) + defer v2.close() + defer v3.close() aliceToken1 := "alice_token_1" aliceToken2 := "alice_token_2" roomID := "!room:test" - v2.addAccount(alice, aliceToken1) + v2.addAccount(t, alice, aliceToken1) t.Log("Prepare to tell a poller using aliceToken1 that Alice created a room and that Bob joined it.") @@ -69,7 +71,7 @@ func TestSyncWithNewTokenAfterOldExpires(t *testing.T) { }) t.Log("Alice refreshes her access token. The old one expires.") - v2.addAccount(alice, aliceToken2) + v2.addAccount(t, alice, aliceToken2) v2.invalidateToken(aliceToken1) t.Log("Alice makes an incremental sliding sync with the new token.") diff --git a/tests-integration/v3_test.go b/tests-integration/v3_test.go index 82c1cef7..a8edc349 100644 --- a/tests-integration/v3_test.go +++ b/tests-integration/v3_test.go @@ -73,11 +73,13 @@ func (s *testV2Server) SetCheckRequest(fn func(userID, token string, req *http.R // Most tests only use a single device per user. Give them this helper so they don't // have to care about providing a device name. -func (s *testV2Server) addAccount(userID, token string) { - // To keep our future selves sane while debugging, use a device name that - // includes the mxid localpart. +func (s *testV2Server) addAccount(t testutils.TestBenchInterface, userID, token string) { + // To keep our future selves sane while debugging use a device name that + // - includes the mxid localpart, and + // - includes the test name (to avoid leaking state from previous tests). atLocalPart, _, _ := strings.Cut(userID, ":") - s.addAccountWithDeviceID(userID, atLocalPart[1:]+"_device", token) + deviceID := fmt.Sprintf("%s_%s_device", atLocalPart[1:], t.Name()) + s.addAccountWithDeviceID(userID, deviceID, token) } // Tests that use multiple devices for the same user need to be more explicit.