Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakey TestRoomReceiptsReadMarkers #393

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}