Skip to content

Commit

Permalink
Use different device names for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed May 15, 2023
1 parent 5503b9d commit 9982ab2
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion tests-integration/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down
22 changes: 11 additions & 11 deletions tests-integration/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions tests-integration/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"}}`),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/invite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down
8 changes: 4 additions & 4 deletions tests-integration/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down
6 changes: 3 additions & 3 deletions tests-integration/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/rig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/room_names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/room_subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/slow_get_all_rooms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down
24 changes: 12 additions & 12 deletions tests-integration/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
Expand Down Expand Up @@ -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...),
Expand Down Expand Up @@ -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...),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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...),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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...),
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 4 additions & 2 deletions tests-integration/token_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")
Expand Down
10 changes: 6 additions & 4 deletions tests-integration/v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9982ab2

Please sign in to comment.