From 70fe974a95c101aef06a36d97ca10c4823f3cd7e Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Wed, 29 Apr 2020 15:04:38 +0300 Subject: [PATCH] satellite/payments/stripecoinpayments: fix test flakyness CustomerRepositoryList relied on created at time for the output sorting, however the granularity of the timer may cause multiple customers having the same "created at" time. Add a sleep so that every customer does get a unique time. Change-Id: If2923174f304fa5f41260d500f6139e3fa7c3ba5 --- .../payments/stripecoinpayments/customers_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/satellite/payments/stripecoinpayments/customers_test.go b/satellite/payments/stripecoinpayments/customers_test.go index 3a04c9359..dcc13e254 100644 --- a/satellite/payments/stripecoinpayments/customers_test.go +++ b/satellite/payments/stripecoinpayments/customers_test.go @@ -61,6 +61,9 @@ func TestCustomersRepositoryList(t *testing.T) { err = customersDB.Insert(ctx, cus.UserID, cus.ID) require.NoError(t, err) + + // Ensure that every insert gets a different "created at" time. + waitForTimeToChange() } page, err := customersDB.List(ctx, 0, custLen, time.Now()) @@ -83,7 +86,6 @@ func TestCustomersRepositoryList(t *testing.T) { for i, cus := range page.Customers { assert.Equal(t, "customerID"+strconv.Itoa(7-i), cus.ID) - } page, err = customersDB.List(ctx, page.NextOffset, custLen, time.Now()) @@ -99,3 +101,10 @@ func TestCustomersRepositoryList(t *testing.T) { } }) } + +func waitForTimeToChange() { + t := time.Now() + for time.Since(t) == 0 { + time.Sleep(5 * time.Millisecond) + } +}