From eff8fa14c68c69f7a1876be59f4dbf4248d88975 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 2 Dec 2021 14:26:13 +0100 Subject: [PATCH] Chore: Fix flaky serverlock integration test (#42633) (#42646) (cherry picked from commit 54fa7b57fe0f9c961259763be2b52b8db7999c1d) --- .../serverlock/serverlock_integration_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/infra/serverlock/serverlock_integration_test.go b/pkg/infra/serverlock/serverlock_integration_test.go index 33d34308db7..752e516dbe1 100644 --- a/pkg/infra/serverlock/serverlock_integration_test.go +++ b/pkg/infra/serverlock/serverlock_integration_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestServerLok(t *testing.T) { @@ -16,21 +16,22 @@ func TestServerLok(t *testing.T) { counter := 0 fn := func() { counter++ } - atInterval := time.Second * 1 + atInterval := time.Hour ctx := context.Background() //this time `fn` should be executed - assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn)) + require.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn)) + require.Equal(t, 1, counter) //this should not execute `fn` - assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn)) - assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn)) + require.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn)) + require.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn)) + require.Equal(t, 1, counter) - // wait 2 second. - <-time.After(time.Second * 2) + atInterval = time.Millisecond // now `fn` should be executed again err := sl.LockAndExecute(ctx, "test-operation", atInterval, fn) - assert.Nil(t, err) - assert.Equal(t, counter, 2) + require.Nil(t, err) + require.Equal(t, 2, counter) }