Cats Actors 2.2.0 is out! Control time in your tests!

Author here. Cats-Actors is an actor library built on Cats Effect: typed messages, functional state, supervision, all in F[_].

The thing this release solves is testing. Actor test suites accumulate sleeps, because the only way to check that a five second timer fired is to wait six seconds and hope the machine is not busy. So the slow paths (long receive timeouts, supervision retry windows) end up untested, since waiting an hour in CI is not an option.

2.2.0 runs the whole actor system inside Cats Effect’s TestControl. Sleeps are not skipped, they are honoured against a clock the test advances itself, so ordering is preserved: work scheduled at five seconds still happens before the six second mark. It just costs no real time. An hour long timeout becomes a deterministic unit test that runs in milliseconds.

The interesting part was what stopped it working before. Anything reading System.currentTimeMillis is invisible to a simulated clock, so those code paths sat still while virtual time ran ahead. Replacing them with Clock[F].monotonic was mostly mechanical, and the constraint was already in scope in most places since Sync extends Clock. Worth knowing if you are doing the same: monotonic for elapsed time, realTime only for actual timestamps.

Scala 2.13 and 3, on JVM, Scala.js and Scala Native.

1 Like