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.
23 lines
488 B
Go
23 lines
488 B
Go
3 years ago
|
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())
|
||
|
time.Sleep(time.Second)
|
||
|
fmt.Println("lock2", lock2.LockWithTimeout(time.Second*5))
|
||
|
fmt.Println("unlock1", lock.Unlock())
|
||
|
time.Sleep(time.Second)
|
||
|
fmt.Println("lock2", lock2.LockNoBlocking())
|
||
|
fmt.Println("unlock2", lock2.Unlock())
|
||
|
os.Remove(filename)
|
||
|
}
|