mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 00:08:10 -05:00
Chore: Fix flaky serverlock integration test (#42633)
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerLok(t *testing.T) {
|
func TestServerLok(t *testing.T) {
|
||||||
@@ -16,21 +16,22 @@ func TestServerLok(t *testing.T) {
|
|||||||
|
|
||||||
counter := 0
|
counter := 0
|
||||||
fn := func(context.Context) { counter++ }
|
fn := func(context.Context) { counter++ }
|
||||||
atInterval := time.Second * 1
|
atInterval := time.Hour
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
//this time `fn` should be executed
|
//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`
|
//this should not execute `fn`
|
||||||
assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn))
|
require.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.Equal(t, 1, counter)
|
||||||
|
|
||||||
// wait 2 second.
|
atInterval = time.Millisecond
|
||||||
<-time.After(time.Second * 2)
|
|
||||||
|
|
||||||
// now `fn` should be executed again
|
// now `fn` should be executed again
|
||||||
err := sl.LockAndExecute(ctx, "test-operation", atInterval, fn)
|
err := sl.LockAndExecute(ctx, "test-operation", atInterval, fn)
|
||||||
assert.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, counter, 2)
|
require.Equal(t, 2, counter)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user