zio-intellij
zio-intellij copied to clipboard
Test fails in ZIO test runner but pass with `sbt test` or regular Intellij app runner
I have the following tests (stripped version of my original ones). When run via IntelliJ ZIO test runner the first one passes but the second one hangs after logging first repetition, although when run either via sbt test
or from IntelliJ using regular app runner both work fine.
import zio.clock.Clock
import zio.duration.durationInt
import zio.logging.Logging
import zio.test.Assertion.equalTo
import zio.test.environment.TestEnvironment
import zio.test.{DefaultRunnableSpec, ZSpec}
import zio.{Has, Promise, Ref, ZIO}
object SimpleSpec extends DefaultRunnableSpec {
private val doWorkLogging = for {
currentCount <- ZIO.accessM[Has[Ref[Long]]](_.get.updateAndGet(_ + 1))
lock <- ZIO.service[Promise[Nothing, Long]]
now <- zio.clock.instant
_ <- zio.logging.log.info(s"Run $now")
_ <- lock.completeWith(ZIO.succeed(currentCount)).when(currentCount == 3)
} yield ()
private val looper = doWorkLogging *> (zio.UIO.unit.delay(1.seconds) *> doWorkLogging).forever
private val logging = Logging.console()
override def spec: ZSpec[Environment, Any] = suite("simple test")(
testM("Clock.live with promise") {
val counter = Ref.make(0L).toLayer
val lock = Promise.make[Nothing, Long].toLayer
(for {
f <- looper.fork
count <- ZIO.accessM[Has[Promise[Nothing, Long]]](_.get.await)
_ <- f.interrupt
} yield zio.test.assert(count)(equalTo(3L))).provideSomeLayer[TestEnvironment](Clock.live ++ lock ++ logging ++ counter)
},
testM("TestClock with promise") {
val counter = Ref.make(0L).toLayer
val lock = Promise.make[Nothing, Long].toLayer
(for {
f <- looper.fork
_ <- zio.test.environment.TestClock.adjust(5.seconds)
count <- ZIO.accessM[Has[Promise[Nothing, Long]]](_.get.await)
_ <- f.interrupt
} yield zio.test.assert(count)(equalTo(3L))).provideSomeLayer[TestEnvironment](lock ++ logging ++ counter)
}
)
}
Similar case: https://github.com/zio/zio/issues/4896
Thank you very much for the repro(s)! I can indeed confirm this happens on my machine too with the runner! Will definitely try to fix soon!