File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ (import (only-in :std/test
2+ test-suite
3+ test-case
4+ check
5+ check-exception)
6+ (only-in :std/error
7+ timeout-error?)
8+ (only-in :std/misc/string
9+ random-string)
10+ (only-in :std/os/fdio
11+ S_IRUSR
12+ S_IWUSR
13+ _open)
14+ (only-in :std/os/fcntl
15+ O_RDONLY
16+ O_CREAT)
17+ (only-in :std/os/temporaries
18+ call-with-temporary-file-name)
19+ (only-in ./flock
20+ flock/block
21+ LOCK_EX
22+ LOCK_SH))
23+ (export flock-test)
24+
25+ (def tmp-prefix " gerbil-flock-test" )
26+ (def flags (fxior O_RDONLY O_CREAT))
27+ (def mode (fxior S_IRUSR S_IWUSR))
28+
29+ (def flock-test
30+ (test-suite " test :std/os/flock"
31+ (test-case " cooperative flock/block"
32+ (call-with-temporary-file-name
33+ tmp-prefix
34+ (lambda (path )
35+ (flock/block (_open path flags mode) LOCK_SH)
36+ (check (flock/block (_open path flags mode) LOCK_SH) ? void?))))
37+
38+ (test-case " uncooperative flock/block"
39+ (call-with-temporary-file-name
40+ tmp-prefix
41+ (lambda (path )
42+ (flock/block (_open path flags mode) LOCK_EX)
43+ (let ((fuse #f ))
44+ (spawn (lambda ()
45+ (thread-sleep! 1 )
46+ (set! fuse #t )))
47+ (check-exception (flock/block (_open path flags mode) LOCK_EX 3 ) timeout-error?)
48+ (check fuse => #t )))))))
Original file line number Diff line number Diff line change 4444 (let lp ()
4545 (unless (flock raw-or-fd op)
4646 (when deadline
47- (unless (< deadline (##current-time-point))
47+ (when (< deadline (##current-time-point))
4848 (raise-timeout flock " Deadline for flock operation exceeded" raw-or-fd op)))
4949 (thread-sleep! (random-real))
5050 (lp))))
You can’t perform that action at this time.
0 commit comments