grafana/pkg/infra/serverlock/serverlock_integration_test.go
Kat Yang bd35e6917a
Chore: Exclude integration tests from running on test-backend step (#50359)
* Chore: Exclude integration tests from running on test-backend step

* Remove -v from go test command

* Add check to skip integration tests before each integration test

* Try to restart pipeline

* Retrying to make pipeline run
2022-06-10 11:46:21 -04:00

38 lines
900 B
Go

package serverlock
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestIntegrationServerLok(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
sl := createTestableServerLock(t)
counter := 0
fn := func(context.Context) { counter++ }
atInterval := time.Hour
ctx := context.Background()
//this time `fn` should be executed
require.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn))
require.Equal(t, 1, counter)
//this should not execute `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)
atInterval = time.Millisecond
// now `fn` should be executed again
err := sl.LockAndExecute(ctx, "test-operation", atInterval, fn)
require.Nil(t, err)
require.Equal(t, 2, counter)
}