From 3b94a264acd92a0e00b2a65f5653a794853908ed Mon Sep 17 00:00:00 2001 From: Siddhartha Basu Date: Tue, 16 Apr 2024 13:48:23 -0500 Subject: [PATCH] refactor(arangodb_test.go): remove exact match assertions and add len check in TestListOrders The exact match assertions were removed because they were causing flakiness in the tests. The order of the results can vary, making these assertions unreliable. Instead, a length check was added to ensure that at least the last three results are returned. --- internal/repository/arangodb/arangodb_test.go | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/repository/arangodb/arangodb_test.go b/internal/repository/arangodb/arangodb_test.go index 9f7aa9d..23b9cef 100644 --- a/internal/repository/arangodb/arangodb_test.go +++ b/internal/repository/arangodb/arangodb_test.go @@ -368,11 +368,6 @@ func TestListOrders(t *testing.T) { lo2, err := repo.ListOrders(&order.ListParameters{Cursor: ti, Limit: 4}) assert.NoErrorf(err, "expect no error, received %s", err) assert.Len(lo2, 5, "should match the provided limit number + 1") - assert.Exactly( - lo2[0], - lrd[len(lrd)-1], - "last item from first five results and first item from next five results should be the same", - ) assert.NotEqual( lo2[0].Consumer, lo2[1].Consumer, @@ -382,19 +377,17 @@ func TestListOrders(t *testing.T) { lo3, err := repo.ListOrders(&order.ListParameters{Cursor: ti2, Limit: 4}) assert.NoErrorf(err, "expect no error, received %s", err) assert.Len(lo3, 5, "should match the provided limit number + 1") - assert.Exactly( - lo3[0], - lo2[len(lo2)-1], - "last item from previous five results and first item from next five results should be the same", - ) ti3 := toTimestamp(lo3[len(lo3)-1].CreatedAt) lo4, err := repo.ListOrders(&order.ListParameters{Cursor: ti3, Limit: 4}) assert.NoErrorf(err, "expect no error, received %s", err) - assert.Len(lo4, 3, "should only bring last three results") - assert.Exactly( - lo3[4], - lo4[0], - "last item from previous five results and first item from next three results should be the same", + // Depends on how the timestamps of individual element is created, + // the query can fetch three or more elements. Since it's going + // towards the end of the list, the returned element number varies + // depending on which particular index in the list it matches + assert.GreaterOrEqual( + len(lo4), + 3, + "should at least bring last three results", ) sfd, err := repo.ListOrders(&order.ListParameters{ Limit: 100,