From bb3c86281c90aa957c7fbdfa5ac6c0cc08b545ef Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Sat, 4 Sep 2021 11:59:23 +0300 Subject: [PATCH] make TestService_UserReplies more robust It flaps (see #380), and with this change, it will have more time to get the expected output in the flaky GitHub Actions environment. --- backend/app/main_test.go | 2 +- backend/app/store/service/service_test.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/app/main_test.go b/backend/app/main_test.go index 232e101b..cf4ab211 100644 --- a/backend/app/main_test.go +++ b/backend/app/main_test.go @@ -99,7 +99,7 @@ func TestMain_WithWebhook(t *testing.T) { finished := make(chan struct{}) go func() { main() - assert.Eventuallyf(t, func() bool { + assert.Eventually(t, func() bool { return atomic.LoadInt32(&webhookSent) == int32(1) }, time.Second, 100*time.Millisecond, "webhook was not sent") close(finished) diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go index 32e2210a..28d6a61c 100644 --- a/backend/app/store/service/service_test.go +++ b/backend/app/store/service/service_test.go @@ -1048,7 +1048,7 @@ func TestService_UserReplies(t *testing.T) { _, err = b.Create(c4) require.NoError(t, err) - time.Sleep(200 * time.Millisecond) + time.Sleep(100 * time.Millisecond) _, err = b.Create(c5) require.NoError(t, err) @@ -1057,10 +1057,12 @@ func TestService_UserReplies(t *testing.T) { require.Equal(t, 3, len(cc), "3 replies to u1") assert.Equal(t, "developer one u1", u) - cc, u, err = b.UserReplies("radio-t", "u1", 10, time.Millisecond*199) - assert.NoError(t, err) - require.Equal(t, 1, len(cc), "1 reply to u1 in last 200ms") - assert.Equal(t, "developer one u1", u) + assert.Eventually(t, func() bool { + cc, u, err = b.UserReplies("radio-t", "u1", 10, time.Millisecond*199) + require.NoError(t, err) + require.Equal(t, "developer one u1", u) + return len(cc) == 1 + }, 300*time.Millisecond, 30*time.Millisecond, "1 reply to u1 in the last 200ms") cc, u, err = b.UserReplies("radio-t", "u2", 10, time.Hour) assert.NoError(t, err)