aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cancel.lua20
1 files changed, 5 insertions, 15 deletions
diff --git a/tests/cancel.lua b/tests/cancel.lua
index c5bb761..c22103f 100644
--- a/tests/cancel.lua
+++ b/tests/cancel.lua
@@ -139,6 +139,7 @@ if not next(which_tests) or which_tests.linda then
139 linda:receive( 1, "yeah") 139 linda:receive( 1, "yeah")
140 140
141 -- linda cancel: linda:receive() returns cancel_error immediately 141 -- linda cancel: linda:receive() returns cancel_error immediately
142 print "cancelling"
142 linda:cancel( "both") 143 linda:cancel( "both")
143 144
144 -- wait until cancellation is effective. 145 -- wait until cancellation is effective.
@@ -163,6 +164,7 @@ if not next(which_tests) or which_tests.soft then
163 waitCancellation( h, "waiting") 164 waitCancellation( h, "waiting")
164 165
165 -- soft cancel, this time awakens waiting linda operations, which returns cancel_error immediately, no timeout. 166 -- soft cancel, this time awakens waiting linda operations, which returns cancel_error immediately, no timeout.
167 print "cancelling"
166 h:cancel( "soft", true) 168 h:cancel( "soft", true)
167 169
168 -- wait until cancellation is effective. the lane will interrupt its loop and print the exit message 170 -- wait until cancellation is effective. the lane will interrupt its loop and print the exit message
@@ -177,6 +179,7 @@ if not next(which_tests) or which_tests.hook then
177 linda:receive( 2, "yeah") 179 linda:receive( 2, "yeah")
178 180
179 -- count hook cancel after some instruction instructions 181 -- count hook cancel after some instruction instructions
182 print "cancelling"
180 h:cancel( "line", 300, 5.0) 183 h:cancel( "line", 300, 5.0)
181 184
182 -- wait until cancellation is effective. the lane will interrupt its loop and print the exit message 185 -- wait until cancellation is effective. the lane will interrupt its loop and print the exit message
@@ -193,6 +196,7 @@ if not next(which_tests) or which_tests.hard then
193 linda:receive( 2, "yeah") 196 linda:receive( 2, "yeah")
194 197
195 -- hard cancel: the lane will be interrupted from inside its current linda:receive() and won't return from it 198 -- hard cancel: the lane will be interrupted from inside its current linda:receive() and won't return from it
199 print "cancelling"
196 h:cancel() 200 h:cancel()
197 201
198 -- wait until cancellation is effective. the lane will be stopped by the linda operation throwing an error 202 -- wait until cancellation is effective. the lane will be stopped by the linda operation throwing an error
@@ -209,27 +213,13 @@ if not next(which_tests) or which_tests.hard_unprotected then
209 linda:receive( 2, "yeah") 213 linda:receive( 2, "yeah")
210 214
211 -- hard cancel: the lane will be interrupted from inside its current linda:receive() and won't return from it 215 -- hard cancel: the lane will be interrupted from inside its current linda:receive() and won't return from it
216 print "cancelling"
212 h:cancel() 217 h:cancel()
213 218
214 -- wait until cancellation is effective. the lane will be stopped by the linda operation throwing an error 219 -- wait until cancellation is effective. the lane will be stopped by the linda operation throwing an error
215 waitCancellation( h, "cancelled") 220 waitCancellation( h, "cancelled")
216end 221end
217 222
218if not next(which_tests) or which_tests.kill then
219 remaining_tests.kill = nil
220 print "\n\n####################################################################\nbegin kill cancel test\n"
221 h = lanes.gen( "*", laneBody)( "busy", 50000000) -- start a pure Lua busy loop lane
222
223 -- wait 1/3s before cancelling the lane, before the busy loop can finish
224 print "wait 0.3s"
225 linda:receive( 0.3, "yeah")
226
227 -- hard cancel with kill: the lane thread will be forcefully terminated. kill timeout is pthread-specific
228 h:cancel( true, 1.0)
229
230 -- wait until cancellation is effective. the lane will be stopped by the linda operation throwing an error
231 waitCancellation( h, "killed")
232end
233--#################################################################### 223--####################################################################
234 224
235local unknown_test, val = next(remaining_tests) 225local unknown_test, val = next(remaining_tests)