cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

TestControl + Dispatcher == deadlock

Open Baccata opened this issue 1 year ago • 13 comments
trafficstars

Using CE 3.5.4, invoking a Dispatcher#unsafeRunSync in a program run with TestControl appears to deadlock

//> using dep "org.typelevel::cats-effect-testkit:3.5.4"

import cats.effect.IOApp
import cats.effect.IO
import cats.effect.std.Dispatcher
import scala.concurrent.duration._
import cats.effect.testkit.TestControl

object Main extends IOApp.Simple {

  // exact same thing happens using parallel 
  val program = Dispatcher.sequential[IO].use { dispatcher =>
    IO(dispatcher.unsafeRunSync(IO(1)))
  }

  def run: IO[Unit] =
    TestControl
      .executeEmbed(program)
      .flatMap(IO.println)
      .timeout(2.seconds)  // timeout doesn't kick-in 

}

Baccata avatar Jul 18 '24 08:07 Baccata