Skip to content

Commit 7576856

Browse files
committed
Add a few more tests
1 parent 08daf3a commit 7576856

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

test/Test/Main.purs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@ test_general_bracket = assert "bracket/general" do
257257
r4 ← readRef ref
258258
pure (isLeft r1 && isLeft r2 && isRight r3 && r4 == "foofoo/kill/zbarbar/throw/bbazcbaz/release/c")
259259

260+
test_supervise eff. TestAff eff Unit
261+
test_supervise = assert "supervise" do
262+
ref ← newRef ""
263+
r1 ← supervise do
264+
_ ← forkAff do
265+
bracket
266+
(modifyRef ref (_ <> "acquire"))
267+
(\_ → modifyRef ref (_ <> "release"))
268+
(\_ → delay (Milliseconds 10.0))
269+
_ ← forkAff do
270+
delay (Milliseconds 11.0)
271+
modifyRef ref (_ <> "delay")
272+
delay (Milliseconds 5.0)
273+
modifyRef ref (_ <> "done")
274+
pure "done"
275+
delay (Milliseconds 20.0)
276+
r2 ← readRef ref
277+
pure (r1 == "done" && r2 == "acquiredonerelease")
278+
260279
test_kill eff. TestAff eff Unit
261280
test_kill = assert "kill" do
262281
fiber ← forkAff never
@@ -401,7 +420,7 @@ test_parallel_alt = assert "parallel/alt" do
401420
pure (r1 == "bar" && r2 == "bar")
402421

403422
test_parallel_alt_sync eff. TestAff eff Unit
404-
test_parallel_alt_sync = assert "kill/parallel/alt/sync" do
423+
test_parallel_alt_sync = assert "parallel/alt/sync" do
405424
ref ← newRef ""
406425
let
407426
action s = do
@@ -416,6 +435,27 @@ test_parallel_alt_sync = assert "kill/parallel/alt/sync" do
416435
r2 ← readRef ref
417436
pure (r1 == "foo" && r2 == "fookilledfoo")
418437

438+
test_parallel_mixed eff. TestAff eff Unit
439+
test_parallel_mixed = assert "parallel/mixed" do
440+
ref ← newRef ""
441+
let
442+
action n s = parallel do
443+
delay (Milliseconds n)
444+
modifyRef ref (_ <> s)
445+
pure s
446+
{ r1, r2, r3 } ← sequential $
447+
{ r1: _, r2: _, r3: _ }
448+
<$> action 10.0 "a"
449+
<*> (action 15.0 "a"
450+
<|> action 12.0 "b"
451+
<|> action 16.0 "c")
452+
<*> (action 15.0 "a"
453+
<|> ((<>) <$> action 13.0 "d" <*> action 14.0 "e")
454+
<|> action 16.0 "f")
455+
delay (Milliseconds 20.0)
456+
r4 ← readRef ref
457+
pure (r1 == "a" && r2 == "b" && r3 == "de" && r4 == "abde")
458+
419459
test_kill_parallel_alt eff. TestAff eff Unit
420460
test_kill_parallel_alt = assert "kill/parallel/alt" do
421461
ref ← newRef ""
@@ -506,6 +546,7 @@ main = do
506546
test_bracket
507547
test_bracket_nested
508548
test_general_bracket
549+
test_supervise
509550
test_kill
510551
test_kill_canceler
511552
test_kill_bracket
@@ -515,6 +556,7 @@ main = do
515556
test_kill_parallel
516557
test_parallel_alt
517558
test_parallel_alt_sync
559+
test_parallel_mixed
518560
test_kill_parallel_alt
519561
test_fiber_map
520562
test_fiber_apply

0 commit comments

Comments
 (0)