Use different device names for each test

This commit is contained in:
David Robertson 2023-05-15 19:11:48 +01:00
parent 5503b9d10b
commit 9982ab24ee
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
15 changed files with 52 additions and 48 deletions

View File

@ -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...),

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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...),

View File

@ -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{

View File

@ -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...),

View File

@ -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.")

View File

@ -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)

View File

@ -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...),

View File

@ -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{

View File

@ -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...),

View File

@ -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{

View File

@ -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.")

View File

@ -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.