renames main lock function

This commit is contained in:
bergquist
2018-12-17 16:36:57 +01:00
parent c565b018c5
commit 11cde7ed71
3 changed files with 14 additions and 12 deletions
@@ -21,19 +21,19 @@ func TestServerLok(t *testing.T) {
ctx := context.Background()
//this time `fn` should be executed
So(sl.OncePerServerGroup(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
//this should not execute `fn`
So(sl.OncePerServerGroup(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.OncePerServerGroup(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.OncePerServerGroup(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
So(sl.OncePerServerGroup(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)
So(sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter), ShouldBeNil)
// wait 5 second.
<-time.After(atInterval * 2)
// now `fn` should be executed again
err = sl.OncePerServerGroup(ctx, "test-operation", atInterval, incCounter)
err = sl.LockAndExecute(ctx, "test-operation", atInterval, incCounter)
So(err, ShouldBeNil)
So(counter, ShouldEqual, 2)
})