package staros import ( "fmt" "os" "testing" "time" ) func Test_FileLock(t *testing.T) { filename := "./test.file" lock := NewFileLock(filename) lock2 := NewFileLock(filename) fmt.Println("lock1", lock.LockNoBlocking(false)) time.Sleep(time.Second) fmt.Println("lock2", lock2.LockWithTimeout(time.Second*5, false)) fmt.Println("unlock1", lock.Unlock()) time.Sleep(time.Second) fmt.Println("unlock2", lock2.Unlock()) fmt.Println("lock2", lock2.LockNoBlocking(true)) fmt.Println("unlock2", lock2.Unlock()) os.Remove(filename) }