@@ -7,34 +7,29 @@ import (
7
7
"testing"
8
8
"time"
9
9
10
- . "github.com/smartystreets/goconvey/convey "
10
+ "github.com/stretchr/testify/assert "
11
11
)
12
12
13
13
func TestServerLok (t * testing.T ) {
14
14
sl := createTestableServerLock (t )
15
15
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 )
40
35
}
0 commit comments