Search code examples
scalaautomated-testscats-effect

How to make virtual time pass in a test in Cats Effect 3?


I am trying to convert Mules to Cats Effect 3 (CE3). Since it is a caching library, in its tests it needs (virtual) time to pass to test whether items will be expired. It is currently making fairly heavy use of cats.effect.laws.util.TestContext, which allows advancing the virtual clock without actually sleeping via tick. TestContext does not (as far as I have been able to discover) exist in CE3, but I am always loathe to puts sleep calls into a test. Rolling my own IO for this specific case though is a daunting prospect; surely this is a more general problem people have. I was not able to find a reference to TestContext in the migration guide, however.

Is there a known upgrade path for this case?


Solution

  • As mentioned by Victor in comments about v3.3.0, this version is released about a day ago and you can see examples for virtual time in Mocking time paragraph in docs