From 4762dbe42e68df54e343766715adb95968726298 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 13 Jun 2022 09:47:06 +0100 Subject: [PATCH 1/2] Fix flakey receipts tests 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). --- tests/csapi/apidoc_room_receipts_test.go | 78 ++++++++++++------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/csapi/apidoc_room_receipts_test.go b/tests/csapi/apidoc_room_receipts_test.go index d8733385..c7873fa4 100644 --- a/tests/csapi/apidoc_room_receipts_test.go +++ b/tests/csapi/apidoc_room_receipts_test.go @@ -9,7 +9,7 @@ import ( ) // tests/10apidoc/37room-receipts.pl -func TestRoomReceiptsReadMarkers(t *testing.T) { +func TestRoomReceipts(t *testing.T) { deployment := Deploy(t, b.BlueprintAlice) defer deployment.Destroy(t) @@ -17,43 +17,43 @@ func TestRoomReceiptsReadMarkers(t *testing.T) { 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") + } + alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{})) +} + +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/read_markers can create read marker + 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) } From 9193cc7e74bc1b21ac7d40ef5d50fde5aea178c8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 13 Jun 2022 13:20:59 +0100 Subject: [PATCH 2/2] Move comments --- tests/csapi/apidoc_room_receipts_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/csapi/apidoc_room_receipts_test.go b/tests/csapi/apidoc_room_receipts_test.go index c7873fa4..5e149ce8 100644 --- a/tests/csapi/apidoc_room_receipts_test.go +++ b/tests/csapi/apidoc_room_receipts_test.go @@ -9,6 +9,8 @@ import ( ) // tests/10apidoc/37room-receipts.pl + +// sytest: POST /rooms/:room_id/receipt can create receipts func TestRoomReceipts(t *testing.T) { deployment := Deploy(t, b.BlueprintAlice) defer deployment.Destroy(t) @@ -16,7 +18,6 @@ func TestRoomReceipts(t *testing.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 eventID := "" alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { if result.Get("type").Str == "m.room.member" { @@ -31,6 +32,7 @@ func TestRoomReceipts(t *testing.T) { 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) @@ -38,7 +40,6 @@ func TestRoomReadMarkers(t *testing.T) { alice := deployment.Client(t, "hs1", "@alice:hs1") roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - // sytest: POST /rooms/:room_id/read_markers can create read marker eventID := "" alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { if result.Get("type").Str == "m.room.member" {