server: auth schema, keys, sessions, connection registry (#17)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
## Data-dir lock (#17): an exclusive advisory lock in the state dir outlives nothing by accident.
|
||||
## Contention between two processes is exercised by the Node harness (the server holds it while
|
||||
## `gm-key --new` must refuse); in-process fcntl locks are per process, so only acquire/release here.
|
||||
import std/[unittest, os, strutils]
|
||||
import instancelock
|
||||
|
||||
proc tmpDir(): string =
|
||||
result = getTempDir() / "ffflock-" & $getCurrentProcessId()
|
||||
removeDir(result)
|
||||
createDir(result)
|
||||
|
||||
suite "instance lock":
|
||||
test "acquires, creates the lock file, releases and re-acquires":
|
||||
let d = tmpDir()
|
||||
defer: removeDir(d)
|
||||
var lock = tryAcquire(d)
|
||||
check lock.held
|
||||
check fileExists(d / InstanceLockName)
|
||||
check readFile(d / InstanceLockName).strip == $getCurrentProcessId()
|
||||
lock.release()
|
||||
check not lock.held
|
||||
var again = tryAcquire(d)
|
||||
check again.held
|
||||
again.release()
|
||||
|
||||
test "release is idempotent":
|
||||
let d = tmpDir()
|
||||
defer: removeDir(d)
|
||||
var lock = tryAcquire(d)
|
||||
lock.release()
|
||||
lock.release()
|
||||
check not lock.held
|
||||
Reference in New Issue
Block a user