mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-12-05 21:00:15 +08:00
36 lines
558 B
Go
36 lines
558 B
Go
//go:build linux || darwin
|
|
|
|
package control
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"syscall"
|
|
"testing"
|
|
)
|
|
|
|
func TestCacheReadersExcludeReclaim(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "cache.lock")
|
|
a, err := WaitReadLock(t.Context(), p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := WaitReadLock(t.Context(), p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a()
|
|
if unlock, err := Lock(p); !errors.Is(err, syscall.EWOULDBLOCK) {
|
|
if unlock != nil {
|
|
unlock()
|
|
}
|
|
t.Fatal(err)
|
|
}
|
|
b()
|
|
unlock, err := Lock(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
unlock()
|
|
}
|