Varakh
165b992629
All checks were successful
/ build (push) Successful in 3m11s
Reviewed-on: #34 Co-authored-by: Varakh <varakh@varakh.de> Co-committed-by: Varakh <varakh@varakh.de>
43 lines
826 B
Go
43 lines
826 B
Go
package util
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
testLockName = "test_lock"
|
|
)
|
|
|
|
func TestLockExpires(t *testing.T) {
|
|
a := assert.New(t)
|
|
|
|
r := NewInMemoryLockRegistry()
|
|
r.LockWithTTL(testLockName, 250*time.Millisecond)
|
|
a.True(r.Exists(testLockName))
|
|
|
|
time.Sleep(251 * time.Millisecond)
|
|
a.False(r.Exists(testLockName))
|
|
}
|
|
|
|
func TestLockNeverExpires(t *testing.T) {
|
|
a := assert.New(t)
|
|
|
|
r := NewInMemoryLockRegistry()
|
|
r.Lock(testLockName)
|
|
a.True(r.Exists(testLockName))
|
|
|
|
time.Sleep(2 * time.Second)
|
|
a.True(r.Exists(testLockName))
|
|
}
|
|
|
|
func TestLockLocksAndUnlocks(t *testing.T) {
|
|
a := assert.New(t)
|
|
|
|
r := NewInMemoryLockRegistry()
|
|
r.LockWithTTL(testLockName, 250*time.Millisecond)
|
|
a.True(r.Exists(testLockName))
|
|
_ = r.Unlock(testLockName)
|
|
a.False(r.Exists(testLockName))
|
|
}
|