scalameta/munit

Expose `waitForCompletion` for overriding

armanbilge opened this issue · 1 comments

This is used to support timeouts for tests.

def munitTimeout: Duration = new FiniteDuration(30, TimeUnit.SECONDS)
private final def waitForCompletion[T](f: () => Future[T]) =
PlatformCompat.waitAtMost(f, munitTimeout, munitExecutionContext)

The Scala Native implementation doesn't support timeouts (due to limitations of the single-threaded runtime). And actually I suspect the JavaScript one is broken too with the default parasitic execution context.

def waitAtMost[T](
startFuture: () => Future[T],
duration: Duration,
ec: ExecutionContext
): Future[T] = {
startFuture()
}

However, it is possible to implement timeouts for Scala Native when also overriding the ExecutionContext with a more sophisticated runtime.

For example the QueueExecutorScheduler in Cats Effect Native supports timeouts. Since we are using the Cats Effect runtime in munit-cats-effect, I would like to be able to support test timeouts there by overriding waitForCompletion.

Of course we could solve this in userland by adding timeouts to the IO-transform in munit-cats-effect, but then it wouldn't work for non-IO-based tests that also happen to be running in a Cats Effect suite.

I decided to solve this in user-land. MUnit timeouts have other caveats, like lack of support for cancellation.