Created
May 28, 2024 20:59
Revisions
-
djspiewak created this gist
May 28, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ "core PC state machine" should { import cats.effect.kernel.{GenConcurrent, Outcome} import cats.effect.kernel.implicits._ import cats.syntax.all._ type F[A] = PureConc[Int, A] val F = GenConcurrent[F] "run finalizers when canceling never" in { val t = for { c <- F.ref(0) latch <- F.deferred[Unit] fib <- F.start((latch.complete(()) *> F.never[Unit]).onCancel(c.update(_ + 1))) _ <- latch.get _ <- fib.cancel v <- c.get } yield v pure.run(t) mustEqual Outcome.Succeeded(Some(1)) } "run finalizers when canceling Deferred#get" in { val t = for { c <- F.ref(0) latch <- F.deferred[Unit] hang <- F.deferred[Unit] fib <- F.start((latch.complete(()) *> hang.get).onCancel(c.update(_ + 1))) _ <- latch.get _ <- fib.cancel v <- c.get } yield v pure.run(t) mustEqual Outcome.Succeeded(Some(1)) } "run finalizers when canceling Fiber#join" in { val t = for { c <- F.ref(0) latch <- F.deferred[Unit] hang <- F.start(F.never[Unit]) fib <- F.start((latch.complete(()) *> hang.join).onCancel(c.update(_ + 1))) _ <- latch.get _ <- fib.cancel v <- c.get } yield v pure.run(t) mustEqual Outcome.Succeeded(Some(1)) } "hang when canceling uncancelable never" in { val t = for { latch <- F.deferred[Unit] f <- F.start((latch.complete(()) *> F.never[Unit]).uncancelable) _ <- latch.get _ <- f.cancel } yield () pure.run(t) mustEqual Outcome.Succeeded(None) } "hang when canceling uncancelable Deferred#get" in { val t = for { latch <- F.deferred[Unit] hang <- F.deferred[Unit] f <- F.start((latch.complete(()) *> hang.get).uncancelable) _ <- latch.get _ <- f.cancel } yield () pure.run(t) mustEqual Outcome.Succeeded(None) } "hang when canceling uncancelable Fiber#join" in { val t = for { latch <- F.deferred[Unit] hang <- F.start(F.never[Unit]) f <- F.start((latch.complete(()) *> hang.join).uncancelable) _ <- latch.get _ <- f.cancel } yield () pure.run(t) mustEqual Outcome.Succeeded(None) } }