-
Notifications
You must be signed in to change notification settings - Fork 91
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
Add cats-effect support for FunSuite and FunFixtures #134
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution! Just a few quick high-level comments. I'm not at all familiar with cats-effect so it would be great if somebody else could review those bits
), | ||
skip in publish := true | ||
) | ||
lazy val tests = crossProject(JSPlatform, JVMPlatform) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the tests project unchanged and introduce instead new source directories like src/test/non-native
for the parts of the cross-build that cats-effect supports. Use .jvmConfigure(_.dependsOn(munitCatsEffect)).jsConfigure(_.dependsOn(munitCatsEffect))
to skip the native dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also fine to have a src/test/cats-effect
directory if that simplifies things. I want to avoid multiple test projects because it's easiest to reason about the build when you can run testsJVM/test
to run all tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I completely understand what you mean :)
I currently have created a new directory munit-cats-effect
at the root of the project.
Would you like to have a new directory in the tests
folder? Or where do you see this new non-native
source directory in the project?
|
||
import scala.concurrent.Promise | ||
|
||
trait CatsEffectFunFixtures extends FunFixtures { self: CatsEffectSuite => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we could somehow support suite-local and test-local resources via Fixture[T]
. The problem is that Fixture[T]
doesn't support async before/after methods but I wonder if that is something we should consider adding to improve this use-case 🤔
I am concerned it would have to be a breaking change unless we introduce something like AsyncFixture[T]
, but I would love to avoid having separate types for sync/async fixtures.
I personally prefer Fixture[T]
over FunFixture[T]
because 1) it's easier to compose them when you have many and 2) they require less boilerplate per test case. It's also useful to have suite-local resources like a database connection.
This doesn't have to be blocking for this PR, I'm just thinking out loud here. We could go ahead and merge this change for now and add Fixture[T]
support separately.
|
||
FunFixture.async( | ||
setup = { testOptions => | ||
implicit val ec = munitExecutionContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK/expected that munitExecutionContext
is parasitic by default? Users can always override it if they want something else. I felt that a parasitic EC was the best default to 1) have deterministic test behaviors and 2) keep stack traces clean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any issue with the parasitic EC
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, as it turns out, this causes deadlock so you are forced to override it. It also doesn't make for a great default imho (at least not for cats-effect), because the failure mode is "oh no there is a deadlock", and you don't expect it to come from your test framework so it can be baffling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SystemFw Could you please open an issue here? https://github.com/typelevel/munit-cats-effect/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's where I'm coming from typelevel/munit-cats-effect#65
I don't expect munit to take any action at this point (I would have opened a PR), but I thought it was interesting to share if someone else comes across the discussion :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, disregard my comment then :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am certainly hungry for this.
|
||
import cats.effect.{ContextShift, IO, Timer} | ||
|
||
abstract class CatsEffectSuite extends FunSuite { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have some open questions on this before I can continue :)
@milanvdm FYI, I'm using the |
@mpilquist Are you fine if I add your |
Go for it :) |
While I endorse the goal of this PR, I would like to strongly suggest to not add this code as a module to this repository; instead keeping it as a separate project. The reason for this is twofold:
Again, I (and others) believe providing this integration is very worthwhile. To quote a cats-effect maintainer:
I'm happy to provide any kind of resource or support you need for this integration to happen, as long as it lives in a separate repository with a separate release lifecycle. |
@larsrh Do you want to add this repository to the scalameta/typelevel/... org specifically? Not sure if I completely understand the reasoning behind having this in a separate repository vs a separate module in munit itself. It feels to me like the arguments you mention are also solved by having it in a separate module but I could be missing something. One reason to keep it in munit would be to make sure the cats-effect module would always be up-to-date with the latest munit changes. In the end, I don't care too much how this is organized tbh :) As long as it happens ¯_(ツ)_/¯ Concretely, next steps:
|
I can offer to host it on
In principle the separate module breaks the dependency cycle. But since all the modules in a repository are typically released together, this is still a problem. The release workflow would look like this:
Happy to help with all of that, just let me know. I suggest |
@larsrh Thanks a lot for the information :) A typelevel repo feels the most logical place to add this library. |
Excellent! I've created a repository, sent you an invite, and created a ticket for me to set up the project boilerplate (typelevel/munit-cats-effect#1). I'll ping you once that's complete. |
@larsrh thank you for pitching in! I sounds like a good idea to maintain the cats-effect integration in a separate repo 👍 |
Closing in favor of https://github.com/typelevel/munit-cats-effect |
Goal
Remarks
Still to do