evolution-gaming / cats-helper

Helpers for cats & cats-effect
MIT License
49 stars 17 forks source link

Fix flaky PureTestSpec, simplify and comment PureTestRunner #146

Closed sirmax closed 2 years ago

sirmax commented 2 years ago

PureTestSpec is flaky since recently. See this build for example.

- is unaffected by infinite background loops *** FAILED ***
  com.evolutiongaming.catshelper.testkit.AbnormalTermination: java.lang.IllegalStateException: Canceled. State(1708049,854021 nanoseconds,TreeSet(Task(1708049,cats.effect.IOFiber$$Lambda$8049/0x00000008020c83e0@7792f512,854022 nanoseconds)),None)
  ...

The failure is caused by a slowdown somewhere in the underlying runtime, probably in the build agent. Here's the test body

    val main = IO.sleep(1.milli)
    val loop = IO.sleep(1.nano).foreverM
    loop.start *> main

Basically, the test runtime has to "tick" 1.nano increments 1 million times before completing the main 1.milli part. Sometimes it fails to do this in 10 seconds of wall-clock time, and the test gets interrupted by the hot loop detection machinery of PureTest.

The fix is trivial – reduce the number of loop ticks needed to complete the main part.


In addition to the test fix this PR also improves the PureTestRunner:

t3hnar commented 2 years ago

Thanks