lock_test.go 490 B

12345678910111213141516171819202122232425262728
  1. package trylock_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/labring/aiproxy/core/common/trylock"
  6. )
  7. func TestMemLock(t *testing.T) {
  8. if !trylock.MemLock("", time.Second) {
  9. t.Error("Expected true, Got false")
  10. }
  11. if trylock.MemLock("", time.Second) {
  12. t.Error("Expected false, Got true")
  13. }
  14. if trylock.MemLock("", time.Second) {
  15. t.Error("Expected false, Got true")
  16. }
  17. time.Sleep(time.Second)
  18. if !trylock.MemLock("", time.Second) {
  19. t.Error("Expected true, Got false")
  20. }
  21. }