Skip to content

Commit b676502

Browse files
authored
Fix flakey TestRoomReceiptsReadMarkers (#393)
We can't do the tests in parallel, as sending a `/receipt` request after a `/read_markers` request on the same event returns an error. (While `/read_markers` will return 200 in the reversed situation).
1 parent d842670 commit b676502

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

tests/csapi/apidoc_room_receipts_test.go

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,52 @@ import (
99
)
1010

1111
// tests/10apidoc/37room-receipts.pl
12-
func TestRoomReceiptsReadMarkers(t *testing.T) {
12+
13+
// sytest: POST /rooms/:room_id/receipt can create receipts
14+
func TestRoomReceipts(t *testing.T) {
15+
deployment := Deploy(t, b.BlueprintAlice)
16+
defer deployment.Destroy(t)
17+
18+
alice := deployment.Client(t, "hs1", "@alice:hs1")
19+
roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
20+
21+
eventID := ""
22+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
23+
if result.Get("type").Str == "m.room.member" {
24+
eventID = result.Get("event_id").Str
25+
return true
26+
}
27+
return false
28+
}))
29+
if eventID == "" {
30+
t.Fatal("did not find an event_id")
31+
}
32+
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{}))
33+
}
34+
35+
// sytest: POST /rooms/:room_id/read_markers can create read marker
36+
func TestRoomReadMarkers(t *testing.T) {
1337
deployment := Deploy(t, b.BlueprintAlice)
1438
defer deployment.Destroy(t)
1539

1640
alice := deployment.Client(t, "hs1", "@alice:hs1")
1741
roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
1842

19-
// sytest: POST /rooms/:room_id/receipt can create receipts
20-
t.Run("Parallel", func(t *testing.T) {
21-
t.Run("POST /rooms/:room_id/receipt can create receipts", func(t *testing.T) {
22-
t.Parallel()
23-
eventID := ""
24-
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
25-
if result.Get("type").Str == "m.room.member" {
26-
eventID = result.Get("event_id").Str
27-
return true
28-
}
29-
return false
30-
}))
31-
if eventID == "" {
32-
t.Fatal("did not find an event_id")
33-
}
34-
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{}))
35-
})
36-
37-
// sytest: POST /rooms/:room_id/read_markers can create read marker
38-
t.Run("POST /rooms/:room_id/read_markers can create read marker", func(t *testing.T) {
39-
t.Parallel()
40-
eventID := ""
41-
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
42-
if result.Get("type").Str == "m.room.member" {
43-
eventID = result.Get("event_id").Str
44-
return true
45-
}
46-
return false
47-
}))
48-
if eventID == "" {
49-
t.Fatal("did not find an event_id")
50-
}
51-
52-
reqBody := client.WithJSONBody(t, map[string]interface{}{
53-
"m.fully_read": eventID,
54-
"m.read": eventID,
55-
})
56-
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "read_markers"}, reqBody)
57-
})
43+
eventID := ""
44+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
45+
if result.Get("type").Str == "m.room.member" {
46+
eventID = result.Get("event_id").Str
47+
return true
48+
}
49+
return false
50+
}))
51+
if eventID == "" {
52+
t.Fatal("did not find an event_id")
53+
}
54+
55+
reqBody := client.WithJSONBody(t, map[string]interface{}{
56+
"m.fully_read": eventID,
57+
"m.read": eventID,
5858
})
59+
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "read_markers"}, reqBody)
5960
}

0 commit comments

Comments
 (0)