diff options
author | Steve Bennett <steveb@workware.net.au> | 2016-08-19 08:54:29 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2016-08-20 11:24:28 +1000 |
commit | def038d816120c9281e8001c24170047996ebfbc (patch) | |
tree | 17afdef43c7f1b46cb5130eca47bd349cf341c2c /tests/lock.test | |
parent | dc7c2751eb01e8aa37740ce494e2857ce11b5ad3 (diff) | |
download | jimtcl-def038d816120c9281e8001c24170047996ebfbc.zip jimtcl-def038d816120c9281e8001c24170047996ebfbc.tar.gz jimtcl-def038d816120c9281e8001c24170047996ebfbc.tar.bz2 |
Fix aio locking on non-linux platforms
And improve the tests
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/lock.test')
-rw-r--r-- | tests/lock.test | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/tests/lock.test b/tests/lock.test index 2fe6ee4..92778d1 100644 --- a/tests/lock.test +++ b/tests/lock.test @@ -10,6 +10,11 @@ source [file dirname [info script]]/testing.tcl +needs constraint jim +# Really we want to check if locking is supported, but there +# is no easy way to do that, so use the existence of os.wait as a proxy +needs cmd os.wait + set fh [open locktest.file w] test lock-1.1 {grab lock} { @@ -29,32 +34,16 @@ test lock-1.4 {release lock again} { } 1 test lock-1.5 {grab lock from sub-process} { - switch [set pid [os.fork]] { - -1 { error "Fork error." } - 0 { - # Child process - $fh lock - sleep 2 - puts $fh [$fh unlock] - exit - } - default { - sleep 1 - set stat [$fh lock] - set stat - } - } + # Run a child process that grabs the lock for 0.5 seconds + set pid [exec [info nameofexecutable] -e {set fh [open locktest.file r+]; $fh lock; sleep 0.5} >/dev/null &] + sleep 0.1 + # Try to grab the lock - should fail + set stat [$fh lock] + sleep 0.5 + set stat } 0 -# fcntl() allows unlock on non-held lock so unlock will always return 1 -#set x [os.wait $pid] -#test lock-1.6 {check unlock in child process} { -# $fh seek 0 start -# $fh read 1 -#} 1 - $fh close file delete locktest.file testreport - |