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
This commit is contained in:
Egon Elbre 2020-04-29 15:04:38 +03:00
parent 588826157b
commit 70fe974a95

View File

@ -61,6 +61,9 @@ func TestCustomersRepositoryList(t *testing.T) {
err = customersDB.Insert(ctx, cus.UserID, cus.ID) err = customersDB.Insert(ctx, cus.UserID, cus.ID)
require.NoError(t, err) require.NoError(t, err)
// Ensure that every insert gets a different "created at" time.
waitForTimeToChange()
} }
page, err := customersDB.List(ctx, 0, custLen, time.Now()) page, err := customersDB.List(ctx, 0, custLen, time.Now())
@ -83,7 +86,6 @@ func TestCustomersRepositoryList(t *testing.T) {
for i, cus := range page.Customers { for i, cus := range page.Customers {
assert.Equal(t, "customerID"+strconv.Itoa(7-i), cus.ID) assert.Equal(t, "customerID"+strconv.Itoa(7-i), cus.ID)
} }
page, err = customersDB.List(ctx, page.NextOffset, custLen, time.Now()) 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)
}
}