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

`executeEmbed` should auto-cede between every step by default

Open armanbilge opened this issue 2 years ago • 0 comments

Although the test runtime and executeEmbed cannot be used to exercise race conditions, it is still very useful for being able to exercise non-deterministic scheduling of fibers. In fact we can get even closer to simulating parallel execution by randomly interleaving the individuals steps of concurrently running fibers, by configuring the test runtime to auto-cede between every step.

Arguably there is no harm to auto-cede between every step. Because fiber scheduling is entirely random, the fiber that auto-ceded may end up being immediately rescheduled anyway (as if it never ceded at all). So we are not ruling out any possible scenarios, we are only expanding them to include more permutations of the various interleavings between concurrently running fibers.

There are certain bugs which cannot be tested without this, for example: https://github.com/typelevel/cats-effect/blob/8d8097815594be405af2fcfddb4c9b599a1d04d4/tests/jvm/src/test/scala/cats/effect/kernel/AsyncPlatformSpec.scala#L46-L69

armanbilge avatar Apr 26 '23 17:04 armanbilge