-
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 support for async fixtures #430
Conversation
Previously, it was not possible to create fixtures that loaded asynchronously. It was possible to work around this limitation on the JVM by awaiting on futures, but there was no workaround for Scala.js. This commit adds support to return futures (and anything that converts to futures) from the beforeAll/beforeEach/afterEach/afterAll methods. Supersedes scalameta#418. This commit is inspired by that PR but uses a different approach: - No new `AsyncFixture[T]` type. This simplies the logic in `MUnitRunner` and reduces the size of the MUnit public API. The downside is that we introduce a breaking change to the existing `Fixture[T]` API, which will require bumping the version to v1.0.0 for the next release. - This approach supports any `Future`-like values by hooking into the default evaluation of test bodies via `munitValueTransforms`. Co-authored-by: Daniel Esik <e.danicheg@yandex.ru>
eaf6fdc
to
69175cb
Compare
I'll try to get back to this PR soon so that it doesn't stay open for too long. |
A bug in Scala 2.11/2.12 made `TimeoutSuite` fail with the new async fixtures. This commit changes how we implement `munitTimeout` to race two futures instead of calling `Await.result`.
a0d3f58
to
65704c9
Compare
65704c9
to
cfc64be
Compare
d277a57
to
8a123cd
Compare
This test case was causing CI failures on Linux that I wasn't able to reproduce on my local MacBook.
5eac47a
to
2598fa6
Compare
Previously, the test suite was using a parasitic execution context.
CI is green now but I haven't properly reviewed the changes yet. There are several moving pieces and still some breaking behavioral changes that need to be documented (for example ordering of fixtures). |
I'd love to get some input on one design decision. We have three options:
The current PR uses Option 2 but I don't like the name |
Just to throw something out there, have you considered |
@gabro I considered it but didn't want to write |
For the record, MUnit has abstracted on the container type |
Ok, I see it would be a tad annoying to deal with the extra type parameter all of the time.
About this, how would one go about implementing |
By converting the Edit: here's an example: https://github.com/typelevel/munit-cats-effect/blob/main/common/shared/src/main/scala/munit/CatsEffectFunFixtures.scala |
So it would extend In this case I'm 👍 for your solution number 3, @olafurpg, seems to be the most ergonomic |
It's a bit confusing, but |
Well, most likely users won't be expected to work with the lifecycle methods directly since Cats Effect already has |
Also confusingly, |
Yes, I'm aware, sorry for the confusion :) I linked that example because it shows the conversion to |
It would be a good exercise to implement the new Fixture API with |
If you publish a snapshot of this PR, I'd be happy to make a PR against munit-cats-effect demonstrating what this might look like. |
Sounds good. I'll try to get this PR in shape before the end of this week. |
Thanks! Really excited about this. |
Previously, the `Fixture` lifecycle methods returned `Any`, which meant that auto-completions would insert `Any` in the result type when auto-generating implementation of a fixture. Now, the `Fixture[T]` class has `Unit` as result types for consistency with older versions of MUnit. Instead, we introduce `AnyFixture[T]` which only needs to be used when comibing a list of `Fixture[T]` and `FutureFixture[T]` (along with 3rdparty fixture classes).
I went ahead and implemented option 3 from the alternatives here #430 (comment) This came out much cleaner compared to the previous implementation where it was very easy to auto-complete |
30c3052
to
9e081b3
Compare
Will go ahead and merge this and cut a milestone release. I have a few more breaking changes that I want to include in the final version of v1.0.0 so please keep that in mind before upgrading everything to the milestone release |
Previously, it was not possible to create fixtures that loaded
asynchronously. It was possible to work around this limitation on the
JVM by awaiting on futures, but there was no workaround for Scala.js.
This commit adds support to return futures (and anything that converts
to futures) from the beforeAll/beforeEach/afterEach/afterAll methods.
Supersedes #418. This commit is
inspired by that PR but uses a different approach:
AsyncFixture[T]
type. This simplies the logic inMUnitRunner
and reduces the size of the MUnit public API.The downside is that we introduce a breaking change to the existing
Fixture[T]
API, which will require bumping the version to v1.0.0for the next release.
Future
-like values by hooking into thedefault evaluation of test bodies via
munitValueTransforms
.Co-authored-by: Daniel Esik e.danicheg@yandex.ru