diff options
Diffstat (limited to 'tests/cancel.lua')
-rw-r--r-- | tests/cancel.lua | 30 |
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 | ||
3 | local linda = lanes.linda() | 3 | local linda = lanes.linda() |
4 | 4 | ||
5 | --#################################################################### | ||
6 | print "\n\n####################################################################\nbegin genlock & genatomic cancel test\n" | ||
7 | |||
8 | -- get a lock and a atomic operator | ||
9 | local lock = lanes.genlock( linda, "lock", 1) | ||
10 | local atomic = lanes.genatomic( linda, "atomic") | ||
11 | |||
12 | -- check that cancelled lindas give cancel_error as they should | ||
13 | linda:cancel() | ||
14 | assert( linda:get( "empty") == lanes.cancel_error) | ||
15 | assert( lanes.genlock( linda, "any", 1) == lanes.cancel_error) | ||
16 | assert( lanes.genatomic( linda, "any") == lanes.cancel_error) | ||
17 | |||
18 | -- check that lock and atomic functions return cancel_error if the linda was cancelled | ||
19 | assert( lock( 1) == lanes.cancel_error) | ||
20 | assert( lock( -1) == lanes.cancel_error) | ||
21 | assert( atomic( 1) == lanes.cancel_error) | ||
22 | |||
23 | -- reset the linda so that the other tests work | ||
24 | linda:cancel( "none") | ||
25 | linda:limit( "lock", -1) | ||
26 | linda:set( "lock") | ||
27 | linda:limit( "atomic", -1) | ||
28 | linda:set( "atomic") | ||
29 | |||
30 | --#################################################################### | ||
31 | |||
5 | local laneBody = function( timeout_) | 32 | local 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") | |||
105 | print "wait 5s" | 132 | print "wait 5s" |
106 | linda:receive( 5, "yeah") | 133 | linda:receive( 5, "yeah") |
107 | 134 | ||
135 | --#################################################################### | ||
136 | |||
108 | print "\ndone" | 137 | print "\ndone" |
138 | |||