Skip to content

Commit d63fb7f

Browse files
committed
Make backfill vs batch less confusing
1 parent e56c872 commit d63fb7f

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

tests/msc2716_test.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestBackfillingHistory(t *testing.T) {
103103
ensureVirtualUserRegistered(t, as, virtualUserLocalpart)
104104

105105
// Insert the most recent chunk of backfilled history
106-
backfillRes := backfillBatchHistoricalMessages(
106+
backfillRes := batchSendHistoricalMessages(
107107
t,
108108
as,
109109
[]string{virtualUserID},
@@ -120,7 +120,7 @@ func TestBackfillingHistory(t *testing.T) {
120120

121121
// Insert another older chunk of backfilled history from the same user.
122122
// Make sure the meta data and joins still work on the subsequent chunk
123-
backfillRes2 := backfillBatchHistoricalMessages(
123+
backfillRes2 := batchSendHistoricalMessages(
124124
t,
125125
as,
126126
[]string{virtualUserID},
@@ -198,7 +198,7 @@ func TestBackfillingHistory(t *testing.T) {
198198
// Insert a backfilled event
199199
virtualUserID2 := "@ricky:hs1"
200200
virtualUserID3 := "@carol:hs1"
201-
backfillRes := backfillBatchHistoricalMessages(
201+
backfillRes := batchSendHistoricalMessages(
202202
t,
203203
as,
204204
[]string{virtualUserID, virtualUserID2, virtualUserID3},
@@ -241,7 +241,7 @@ func TestBackfillingHistory(t *testing.T) {
241241
createMessagesInRoom(t, alice, roomID, 5)
242242

243243
// Insert a backfilled event
244-
backfillRes := backfillBatchHistoricalMessages(
244+
backfillRes := batchSendHistoricalMessages(
245245
t,
246246
as,
247247
[]string{virtualUserID},
@@ -277,7 +277,7 @@ func TestBackfillingHistory(t *testing.T) {
277277

278278
roomID := as.CreateRoom(t, struct{}{})
279279

280-
backfillBatchHistoricalMessages(
280+
batchSendHistoricalMessages(
281281
t,
282282
as,
283283
[]string{virtualUserID},
@@ -304,7 +304,7 @@ func TestBackfillingHistory(t *testing.T) {
304304
eventIdBefore := eventIDsBefore[0]
305305
timeAfterEventBefore := time.Now()
306306

307-
backfillBatchHistoricalMessages(
307+
batchSendHistoricalMessages(
308308
t,
309309
alice,
310310
[]string{virtualUserID},
@@ -341,7 +341,7 @@ func TestBackfillingHistory(t *testing.T) {
341341
// Register and join the virtual user
342342
ensureVirtualUserRegistered(t, as, virtualUserLocalpart)
343343

344-
backfillRes := backfillBatchHistoricalMessages(
344+
backfillRes := batchSendHistoricalMessages(
345345
t,
346346
as,
347347
[]string{virtualUserID},
@@ -399,7 +399,7 @@ func TestBackfillingHistory(t *testing.T) {
399399
// Register and join the virtual user
400400
ensureVirtualUserRegistered(t, as, virtualUserLocalpart)
401401

402-
backfillRes := backfillBatchHistoricalMessages(
402+
backfillRes := batchSendHistoricalMessages(
403403
t,
404404
as,
405405
[]string{virtualUserID},
@@ -455,7 +455,7 @@ func TestBackfillingHistory(t *testing.T) {
455455
}))
456456

457457
// Historical messages are inserted where we have already scrolled back to
458-
backfillRes := backfillBatchHistoricalMessages(
458+
backfillRes := batchSendHistoricalMessages(
459459
t,
460460
as,
461461
[]string{virtualUserID},
@@ -560,7 +560,7 @@ func createMessagesInRoom(t *testing.T, c *client.CSAPI, roomID string, count in
560560

561561
var chunkCount int64 = 0
562562

563-
func backfillBatchHistoricalMessages(
563+
func batchSendHistoricalMessages(
564564
t *testing.T,
565565
c *client.CSAPI,
566566
virtualUserIDs []string,
@@ -569,7 +569,7 @@ func backfillBatchHistoricalMessages(
569569
insertTime time.Time,
570570
chunkID string,
571571
count int,
572-
status int,
572+
expectedStatus int,
573573
) (res *http.Response) {
574574
// Timestamp in milliseconds
575575
insertOriginServerTs := uint64(insertTime.UnixNano() / int64(time.Millisecond))
@@ -627,16 +627,10 @@ func backfillBatchHistoricalMessages(
627627
client.WithContentType("application/json"),
628628
client.WithQueries(query),
629629
)
630-
// Save the body so we can re-create after the buffer closes
631-
body := client.ParseJSON(t, res)
632-
// Since the original body can only be read once, create a new one from the body bytes we just read
633-
res.Body = ioutil.NopCloser(bytes.NewBuffer(body))
634-
must.MatchResponse(t, res, match.HTTPResponse{
635-
StatusCode: status,
636-
})
637-
// After using up the body in the must.MatchResponse above, create the body again
638-
// Since the original body can only be read once, create a new one from the body bytes we just read
639-
res.Body = ioutil.NopCloser(bytes.NewBuffer(body))
630+
631+
if res.StatusCode != expectedStatus {
632+
t.Fatalf("msc2716.batchSendHistoricalMessages got %d HTTP status code from batch send response but want %d", res.StatusCode, expectedStatus)
633+
}
640634

641635
chunkCount++
642636

0 commit comments

Comments
 (0)