Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override munit ExecutionContext with one from IORuntime #124

Merged
merged 11 commits into from
Sep 14, 2021

Conversation

milanvdm
Copy link
Member

Closes #110

This overrides the default munit parasitic-execution-context with the one from IORuntime.global.

Not sure if tests can be added for ScalaJS on the issue that @djspiewak mentions as I have no ScalaJS knowledge.

@milanvdm
Copy link
Member Author

The tests seem to be flaky. I will investigate further tomorrow as there is no clear test failing as far as I can tell.

@milanvdm
Copy link
Member Author

milanvdm commented Sep 3, 2021

This PR is currently blocked by a bug in cats-effect in the blocking part of the compute pool. I will follow up once fixed.

@milanvdm milanvdm marked this pull request as draft September 4, 2021 20:30
@milanvdm milanvdm marked this pull request as ready for review September 8, 2021 08:17
Copy link
Member

@danicheg danicheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The question is for my understanding rather than any block on this.


abstract class CatsEffectSuite
extends FunSuite
with CatsEffectAssertions
with CatsEffectFixtures
with CatsEffectFunFixtures {

implicit val ioRuntime: IORuntime = IORuntime.global
implicit def munitIoRuntime: IORuntime = IORuntime.global
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why was val changed on def here. IORuntime.global is a val though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When offering an interface to a user, they might want to overwrite this munitIoRuntime with a def.

The same reason that munit itself has the munitExecutionContext as a def on the class we are overwriting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it, thanks. Seems reasonable 👍🏻

@milanvdm milanvdm requested a review from mpilquist September 14, 2021 07:07
@milanvdm milanvdm merged commit 51288ff into typelevel:main Sep 14, 2021
@milanvdm milanvdm deleted the test-scalajs-execution-context branch September 14, 2021 12:12
@vasilmkd
Copy link
Member

vasilmkd commented Oct 1, 2021

@milanvdm @armanbilge Maybe it is best to revert this change and wait until Cats Effect 3.3 releases to incorporate it.

@vasilmkd
Copy link
Member

vasilmkd commented Oct 1, 2021

On the other hand, maybe it is not wise to have this change on the JVM at all. Every time a Future is awaited on the compute pool, it would send a signal to the pool to start new threads. And in huge test suites, that could result in thousands of threads being created. I don't know what exactly to think.

@vasilmkd
Copy link
Member

vasilmkd commented Oct 1, 2021

Please also don't rush to make changes, we'll continue to monitor the possible implications of this PR.

@armanbilge
Copy link
Member

every time a Future is awaited on the compute pool, it would send a signal to the pool to start new threads. And in huge test suites, that could result in thousands of threads being created.

IIUC from our Discord discussion, there is (at least) one Future created per test, when the IO is converted.

The munit docs say that

MUnit does not support running individual test cases in parallel. However, sbt automatically parallelizes the execution of multiple test suites.

So, won't the number of these per-test Futures be bounded by the overall parallelism level that sbt is using?

@vasilmkd
Copy link
Member

vasilmkd commented Oct 2, 2021

I published cats-effect and munit-cats-effect-3 local versions which print when new threads are started, and this seems to not spawn anything in coreJVM/test on fs2, so we're good. I guess I underestimated how these things work. Let's keep it for now.

@ahjohannessen
Copy link
Contributor

This change seems to fail fs2-grpc server streaming tests with regards to cancellation. Not sure what is happening, but restoring the previous execution context in Fs2GrpcSuite makes tests pass again:

  private val parasiticExecutionContext = new ExecutionContext {
    def execute(runnable: Runnable): Unit = runnable.run()
    def reportFailure(cause: Throwable): Unit = cause.printStackTrace()
  }

  override val munitExecutionContext: ExecutionContext = parasiticExecutionContext

@vasilmkd
Copy link
Member

@ahjohannessen Thanks for the pointer, I will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Override MUnit's ExecutionContext on ScalaJS and CE3
6 participants