aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2018-11-08 18:02:17 +0100
committerBenoit Germain <bnt.germain@gmail.com>2018-11-08 18:02:17 +0100
commitb899b53286e9125f34fd7522f4a173ff12643b68 (patch)
tree629bfe6cc462215f82e1a7faee29aaf6161449bd
parent0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 (diff)
downloadlanes-b899b53286e9125f34fd7522f4a173ff12643b68.tar.gz
lanes-b899b53286e9125f34fd7522f4a173ff12643b68.tar.bz2
lanes-b899b53286e9125f34fd7522f4a173ff12643b68.zip
Improved deadlock bug test script
-rw-r--r--tests/deadlock.lua29
1 files changed, 19 insertions, 10 deletions
diff --git a/tests/deadlock.lua b/tests/deadlock.lua
index 8ccae89..655fad2 100644
--- a/tests/deadlock.lua
+++ b/tests/deadlock.lua
@@ -1,28 +1,37 @@
1-- this script tests the fix of a bug that could cause the mutex of a keeper state to remain locked
2-- see https://github.com/LuaLanes/lanes/commit/0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729
3
1local lanes = require('lanes').configure() 4local lanes = require('lanes').configure()
2local linda = lanes.linda "deadlock_linda" 5local linda = lanes.linda "deadlock_linda"
3 6
4local do_extra_stuff = true 7local do_extra_stuff = true
5 8
6if do_extra_stuff then 9if do_extra_stuff then
7 -- just something to make send() succeed and receive() fail: 10 -- just something to make send() succeed and receive() fail (any C function exposed by some module will do)
8 local payload = { lanes.require('socket').connect } 11 local payload = { lanes.require('socket').connect }
9 12
10 -- lane generator 13 -- lane generator
11 local g = lanes.gen('*', function() 14 local g = lanes.gen('*', function()
12 set_debug_threadname "deadlock_lane" 15 set_debug_threadname( "deadlock_lane")
13 print("In lane 1:", table.unpack{pcall(linda.receive, linda, 'tmp')}) 16 -- wrapping inside pcall makes the Lanes module unaware that something went wrong
14 print("In lane 2:", table.unpack{pcall(linda.receive, linda, 'tmp')}) 17 print( "In lane 1:", table.unpack{ pcall( linda.receive, linda, 'tmp')})
18 -- with the bug not fixed, and non-recursive mutexes, we can hang here
19 print( "In lane 2:", table.unpack{ pcall( linda.receive, linda, 'tmp')})
20 -- return something out of the lane
15 return 33, 55 21 return 33, 55
16 end) 22 end)
17 23
18 -- send payload twice 24 -- send payload twice. succeeds because sending stores a function identification string in the linda's keeper state
19 linda:send('tmp', payload, payload) 25 linda:send( 'tmp', payload, payload)
26 -- start the lane
20 local h = g() 27 local h = g()
28 -- wait for lane completion
21 local err, stack = h:join() 29 local err, stack = h:join()
22 print('we reach here and then deadlock', err, stack) 30 print( 'result of lane execution', err, stack)
23end 31end
24-- start lane
25 32
26-- wait some 33-- With the bug not fixed, the linda keeper's mutex is still acquired,
34-- and the program hangs when the internal linda used for timers attempts to acquire the same keeper (there is only one by default)
35print('waiting a bit')
27lanes.sleep(2) 36lanes.sleep(2)
28print('we never reach here') \ No newline at end of file 37print('we should reach here') \ No newline at end of file