Skip to content

Commit 3df94c6

Browse files
authored
serverlock: run tests async should be more linear time wise (grafana#17059)
1 parent 6c7224c commit 3df94c6

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

pkg/infra/serverlock/serverlock_integration_test.go

+20-25
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,29 @@ import (
77
"testing"
88
"time"
99

10-
. "github.com/smartystreets/goconvey/convey"
10+
"github.com/stretchr/testify/assert"
1111
)
1212

1313
func TestServerLok(t *testing.T) {
1414
sl := createTestableServerLock(t)
1515

16-
Convey("Server lock integration tests", t, func() {
17-
counter := 0
18-
var err error
19-
incCounter := func() { counter++ }
20-
atInterval := time.Second * 1
21-
ctx := context.Background()
22-
23-
//this time `fn` should be executed
24-
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
25-
26-
//this should not execute `fn`
27-
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
28-
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
29-
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
30-
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
31-
32-
// wait 5 second.
33-
<-time.After(atInterval * 2)
34-
35-
// now `fn` should be executed again
36-
err = sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter)
37-
So(err, ShouldBeNil)
38-
So(counter, ShouldEqual, 2)
39-
})
16+
counter := 0
17+
fn := func() { counter++ }
18+
atInterval := time.Second * 1
19+
ctx := context.Background()
20+
21+
//this time `fn` should be executed
22+
assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn))
23+
24+
//this should not execute `fn`
25+
assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn))
26+
assert.Nil(t, sl.LockAndExecute(ctx, "test-operation", atInterval, fn))
27+
28+
// wait 2 second.
29+
<-time.After(time.Second * 2)
30+
31+
// now `fn` should be executed again
32+
err := sl.LockAndExecute(ctx, "test-operation", atInterval, fn)
33+
assert.Nil(t, err)
34+
assert.Equal(t, counter, 2)
4035
}

0 commit comments

Comments
 (0)