staros/files_test.go

24 lines
544 B
Go
Raw Permalink Normal View History

2021-09-01 11:01:51 +08:00
package staros
import (
"fmt"
"os"
"testing"
"time"
)
func Test_FileLock(t *testing.T) {
filename := "./test.file"
lock := NewFileLock(filename)
lock2 := NewFileLock(filename)
2021-09-01 13:52:43 +08:00
fmt.Println("lock1", lock.LockNoBlocking(false))
2021-09-01 11:01:51 +08:00
time.Sleep(time.Second)
2021-09-01 13:52:43 +08:00
fmt.Println("lock2", lock2.LockWithTimeout(time.Second*5, false))
2021-09-01 11:01:51 +08:00
fmt.Println("unlock1", lock.Unlock())
time.Sleep(time.Second)
2021-09-01 13:52:43 +08:00
fmt.Println("unlock2", lock2.Unlock())
fmt.Println("lock2", lock2.LockNoBlocking(true))
2021-09-01 11:01:51 +08:00
fmt.Println("unlock2", lock2.Unlock())
os.Remove(filename)
}