From beea2432e6144a98370138f8d3f6334c19a044bb Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 22 Dec 2022 11:31:54 +0100 Subject: [PATCH] Fix flakey test --- federationapi/storage/tables/inbound_peeks_table_test.go | 9 +++++---- .../storage/tables/outbound_peeks_table_test.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/federationapi/storage/tables/inbound_peeks_table_test.go b/federationapi/storage/tables/inbound_peeks_table_test.go index 3a76a857..e5d898b3 100644 --- a/federationapi/storage/tables/inbound_peeks_table_test.go +++ b/federationapi/storage/tables/inbound_peeks_table_test.go @@ -13,6 +13,7 @@ import ( "github.com/matrix-org/dendrite/test" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" + "github.com/stretchr/testify/assert" ) func mustCreateInboundpeeksTable(t *testing.T, dbType test.DBType) (tables.FederationInboundPeeks, func()) { @@ -124,11 +125,11 @@ func TestInboundPeeksTable(t *testing.T) { if len(inboundPeeks) != len(peekIDs) { t.Fatalf("inserted %d peeks, selected %d", len(peekIDs), len(inboundPeeks)) } - for i := range inboundPeeks { - if inboundPeeks[i].PeekID != peekIDs[i] { - t.Fatalf("") - } + gotPeekIDs := make([]string, 0, len(inboundPeeks)) + for _, p := range inboundPeeks { + gotPeekIDs = append(gotPeekIDs, p.PeekID) } + assert.ElementsMatch(t, gotPeekIDs, peekIDs) // And delete them again if err = tab.DeleteInboundPeeks(ctx, nil, room.ID); err != nil { diff --git a/federationapi/storage/tables/outbound_peeks_table_test.go b/federationapi/storage/tables/outbound_peeks_table_test.go index dad6b982..a460af09 100644 --- a/federationapi/storage/tables/outbound_peeks_table_test.go +++ b/federationapi/storage/tables/outbound_peeks_table_test.go @@ -13,6 +13,7 @@ import ( "github.com/matrix-org/dendrite/test" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" + "github.com/stretchr/testify/assert" ) func mustCreateOutboundpeeksTable(t *testing.T, dbType test.DBType) (tables.FederationOutboundPeeks, func()) { @@ -124,11 +125,11 @@ func TestOutboundPeeksTable(t *testing.T) { if len(outboundPeeks) != len(peekIDs) { t.Fatalf("inserted %d peeks, selected %d", len(peekIDs), len(outboundPeeks)) } - for i := range outboundPeeks { - if outboundPeeks[i].PeekID != peekIDs[i] { - t.Fatalf("") - } + gotPeekIDs := make([]string, 0, len(outboundPeeks)) + for _, p := range outboundPeeks { + gotPeekIDs = append(gotPeekIDs, p.PeekID) } + assert.ElementsMatch(t, gotPeekIDs, peekIDs) // And delete them again if err = tab.DeleteOutboundPeeks(ctx, nil, room.ID); err != nil {