The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/infra/serverlock/serverlock_integration_test.go

40 lines
1.1 KiB

// +build integration
package serverlock
import (
"context"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestServerLok(t *testing.T) {
sl := createTestableServerLock(t)
Convey("Server lock integration tests", t, func() {
counter := 0
var err error
incCounter := func() { counter++ }
atInterval := time.Second * 1
ctx := context.Background()
//this time `fn` should be executed
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
//this should not execute `fn`
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
// wait 5 second.
<-time.After(atInterval * 2)
// now `fn` should be executed again
err = sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter)
So(err, ShouldBeNil)
So(counter, ShouldEqual, 2)
})
}