Skip to content

Commit

Permalink
Fix flakey TestRoomReceiptsReadMarkers (#393)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
erikjohnston authored Jun 13, 2022
1 parent d842670 commit b676502
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions tests/csapi/apidoc_room_receipts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,52 @@ import (
)

// tests/10apidoc/37room-receipts.pl
func TestRoomReceiptsReadMarkers(t *testing.T) {

// sytest: POST /rooms/:room_id/receipt can create receipts
func TestRoomReceipts(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)

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

eventID := ""
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
if result.Get("type").Str == "m.room.member" {
eventID = result.Get("event_id").Str
return true
}
return false
}))
if eventID == "" {
t.Fatal("did not find an event_id")
}
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{}))
}

// sytest: POST /rooms/:room_id/read_markers can create read marker
func TestRoomReadMarkers(t *testing.T) {
deployment := Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)

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

// sytest: POST /rooms/:room_id/receipt can create receipts
t.Run("Parallel", func(t *testing.T) {
t.Run("POST /rooms/:room_id/receipt can create receipts", func(t *testing.T) {
t.Parallel()
eventID := ""
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
if result.Get("type").Str == "m.room.member" {
eventID = result.Get("event_id").Str
return true
}
return false
}))
if eventID == "" {
t.Fatal("did not find an event_id")
}
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{}))
})

// sytest: POST /rooms/:room_id/read_markers can create read marker
t.Run("POST /rooms/:room_id/read_markers can create read marker", func(t *testing.T) {
t.Parallel()
eventID := ""
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
if result.Get("type").Str == "m.room.member" {
eventID = result.Get("event_id").Str
return true
}
return false
}))
if eventID == "" {
t.Fatal("did not find an event_id")
}

reqBody := client.WithJSONBody(t, map[string]interface{}{
"m.fully_read": eventID,
"m.read": eventID,
})
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "read_markers"}, reqBody)
})
eventID := ""
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool {
if result.Get("type").Str == "m.room.member" {
eventID = result.Get("event_id").Str
return true
}
return false
}))
if eventID == "" {
t.Fatal("did not find an event_id")
}

reqBody := client.WithJSONBody(t, map[string]interface{}{
"m.fully_read": eventID,
"m.read": eventID,
})
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "read_markers"}, reqBody)
}

0 comments on commit b676502

Please sign in to comment.