lock_test.go 610 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestLock(t *testing.T) {
  7. var (
  8. key string
  9. ok bool
  10. err error
  11. )
  12. Convey("TEST Lock", t, func() {
  13. ok, err = d.TryLock(ctx, key, "test", 1)
  14. So(err, ShouldBeNil)
  15. So(ok, ShouldBeTrue)
  16. ok, err = d.TryLock(ctx, key, "test", 1)
  17. So(err, ShouldBeNil)
  18. So(ok, ShouldBeFalse)
  19. err = d.UnLock(ctx, key)
  20. So(err, ShouldBeNil)
  21. ok, err = d.TryLock(ctx, key, "test", 1)
  22. So(err, ShouldBeNil)
  23. So(ok, ShouldBeTrue)
  24. ok, err = d.TryLock(ctx, key, "test", 1)
  25. So(err, ShouldBeNil)
  26. So(ok, ShouldBeFalse)
  27. })
  28. }