You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
staros/files_test.go

24 lines
544 B
Go

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)
}