aboutsummaryrefslogtreecommitdiff
path: root/tests/cancel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cancel.lua')
-rw-r--r--tests/cancel.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/cancel.lua b/tests/cancel.lua
index a5f1dab..6429487 100644
--- a/tests/cancel.lua
+++ b/tests/cancel.lua
@@ -2,6 +2,33 @@ local lanes = require "lanes" .configure{ with_timers = false}
2 2
3local linda = lanes.linda() 3local linda = lanes.linda()
4 4
5--####################################################################
6print "\n\n####################################################################\nbegin genlock & genatomic cancel test\n"
7
8-- get a lock and a atomic operator
9local lock = lanes.genlock( linda, "lock", 1)
10local atomic = lanes.genatomic( linda, "atomic")
11
12-- check that cancelled lindas give cancel_error as they should
13linda:cancel()
14assert( linda:get( "empty") == lanes.cancel_error)
15assert( lanes.genlock( linda, "any", 1) == lanes.cancel_error)
16assert( lanes.genatomic( linda, "any") == lanes.cancel_error)
17
18-- check that lock and atomic functions return cancel_error if the linda was cancelled
19assert( lock( 1) == lanes.cancel_error)
20assert( lock( -1) == lanes.cancel_error)
21assert( atomic( 1) == lanes.cancel_error)
22
23-- reset the linda so that the other tests work
24linda:cancel( "none")
25linda:limit( "lock", -1)
26linda:set( "lock")
27linda:limit( "atomic", -1)
28linda:set( "atomic")
29
30--####################################################################
31
5local laneBody = function( timeout_) 32local laneBody = function( timeout_)
6 set_finalizer( function( err, stk) 33 set_finalizer( function( err, stk)
7 if err == lanes.cancel_error then 34 if err == lanes.cancel_error then
@@ -105,4 +132,7 @@ linda:cancel( "both")
105print "wait 5s" 132print "wait 5s"
106linda:receive( 5, "yeah") 133linda:receive( 5, "yeah")
107 134
135--####################################################################
136
108print "\ndone" 137print "\ndone"
138