aio tempname: Fix a crash when the template is invalid
[jimtcl.git] / tests / lock.test
blob3672d6ae907f4e11c9df89ca63b5c740dae9daf6
1 # This test file covers POSIX file locking
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # for errors.  No output means no errors were found.
7 # Copyright (c) 2003-2009 Donal K. Fellows
8 # See the file "license.terms" for information on usage and redistribution of
9 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 source [file dirname [info script]]/testing.tcl
13 needs constraint jim
14 testConstraint aio.lock [expr {"lock" in [stdin -commands]}]
15 needs constraint aio.lock
17 set fh [open locktest.file w]
19 test lock-1.1 {grab lock} {
20         $fh lock
21 } 1
23 test lock-1.2 {grab lock again} {
24         $fh lock
25 } 1
27 test lock-1.j {release lock} {
28         $fh unlock
29 } 1
31 test lock-1.4 {release lock again} {
32         $fh unlock
33 } 1
35 test lock-1.5 {grab lock from sub-process} {
36         # Run a child process that grabs the lock for 0.5 seconds
37         set pid [exec [info nameofexecutable] -e {set fh [open locktest.file r+]; $fh lock; sleep 0.5} >/dev/null &]
38         sleep 0.1
39         # Try to grab the lock - should fail
40         set stat [$fh lock]
41         sleep 0.5
42         set stat
43 } 0
45 $fh close
46 file delete locktest.file
48 testreport