Skip to content

Commit

Permalink
make TestService_UserReplies more robust
Browse files Browse the repository at this point in the history
It flaps (see #380), and with this change, it will
have more time to get the expected output in
the flaky GitHub Actions environment.
  • Loading branch information
paskal committed Sep 4, 2021
1 parent 91441d1 commit 468cf01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions backend/app/store/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 468cf01

Please sign in to comment.