Skip to content

Commit dbc5e0f

Browse files
author
Felix Schlitter
committed
Add failing test for #174
1 parent 390857f commit dbc5e0f

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

src/Effect/Aff.js

+36-5
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,15 @@ var Aff = function () {
357357
if (bhead === null) {
358358
attempts = new Aff(CONS, step, attempts, interrupt);
359359
} else {
360-
attempts = new Aff(CONS, step, new Aff(CONS, new Aff(RESUME, bhead, btail), attempts, interrupt), interrupt);
360+
attempts = new Aff(CONS,
361+
step,
362+
new Aff(CONS,
363+
new Aff(RESUME,
364+
bhead,
365+
btail),
366+
attempts,
367+
interrupt),
368+
interrupt);
361369
}
362370
bhead = null;
363371
btail = null;
@@ -370,9 +378,21 @@ var Aff = function () {
370378
case BRACKET:
371379
bracketCount++;
372380
if (bhead === null) {
373-
attempts = new Aff(CONS, step, attempts, interrupt);
381+
attempts = new Aff(CONS,
382+
step,
383+
attempts,
384+
interrupt);
374385
} else {
375-
attempts = new Aff(CONS, step, new Aff(CONS, new Aff(RESUME, bhead, btail), attempts, interrupt), interrupt);
386+
attempts =
387+
new Aff(CONS,
388+
step,
389+
new Aff(CONS,
390+
new Aff(RESUME,
391+
bhead,
392+
btail),
393+
attempts,
394+
interrupt),
395+
interrupt);
376396
}
377397
bhead = null;
378398
btail = null;
@@ -455,7 +475,12 @@ var Aff = function () {
455475
result = util.fromRight(step);
456476
// We need to enqueue the Release with the same interrupt
457477
// status as the Bracket that is initiating it.
458-
attempts = new Aff(CONS, new Aff(RELEASE, attempt._2, result), attempts, tmp);
478+
attempts = new Aff(CONS,
479+
new Aff(RELEASE,
480+
attempt._2,
481+
result),
482+
attempts,
483+
tmp);
459484
// We should only coninue as long as the interrupt status has not changed or
460485
// we are currently within a non-interruptable finalizer.
461486
if (interrupt === tmp || bracketCount > 0) {
@@ -468,13 +493,19 @@ var Aff = function () {
468493
// Enqueue the appropriate handler. We increase the bracket count
469494
// because it should not be cancelled.
470495
case RELEASE:
471-
attempts = new Aff(CONS, new Aff(FINALIZED, step, fail), attempts, interrupt);
496+
attempts = new Aff(CONS,
497+
new Aff(FINALIZED,
498+
step,
499+
fail),
500+
attempts,
501+
interrupt);
472502
status = CONTINUE;
473503
// It has only been killed if the interrupt status has changed
474504
// since we enqueued the item, and the bracket count is 0. If the
475505
// bracket count is non-zero then we are in a masked state so it's
476506
// impossible to be killed.
477507
if (interrupt && interrupt !== tmp && bracketCount === 0) {
508+
console.log(attempt)
478509
step = attempt._1.killed(util.fromLeft(interrupt))(attempt._2);
479510
} else if (fail) {
480511
step = attempt._1.failed(util.fromLeft(fail))(attempt._2);

test/Test/Main.purs

+21
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,26 @@ test_regression_kill_empty_supervisor = assert "regression/kill-empty-supervisor
730730
b = parallel $ delay (Milliseconds 20.0) $> false
731731
sequential (a <|> b)
732732

733+
test_invincible_completes Aff Unit
734+
test_invincible_completes = assert "test/invincible-completes" do
735+
ref ← newRef Nothing
736+
f1 ← forkAff $
737+
generalBracket
738+
(pure unit)
739+
{ killed: \_ _ -> writeRef ref (Just "killed")
740+
, failed: \_ _ -> writeRef ref (Just "failed")
741+
, completed: \_ _ -> writeRef ref (Just "completed")
742+
}
743+
(\_ ->
744+
bracket
745+
(delay (Milliseconds 20.0))
746+
(const (pure unit))
747+
pure
748+
)
749+
delay (Milliseconds 10.0)
750+
killFiber (error "kaboom.") f1
751+
readRef ref <#> (_ == Just "completed")
752+
733753
main Effect Unit
734754
main = do
735755
test_pure
@@ -781,3 +801,4 @@ main = do
781801
test_regression_kill_sync_async
782802
test_regression_bracket_kill_mask
783803
test_regression_kill_empty_supervisor
804+
test_invincible_completes

0 commit comments

Comments
 (0)