-
Notifications
You must be signed in to change notification settings - Fork 6
test: use runTest of coroutines.test instead of runBlocking
#417
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #417 +/- ##
==========================================
+ Coverage 81.90% 81.96% +0.06%
==========================================
Files 152 152
Lines 4879 4879
Branches 846 846
==========================================
+ Hits 3996 3999 +3
+ Misses 563 560 -3
Partials 320 320 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Which is why I decided to not use suspending test functions when I updated to JUnit 6 😀 Is there anything in particular that would benefit from a migration now already? |
We could anyway use This would have some benefits:
|
runBlockingrunTest of coroutines.test instead of runBlocking
JUnit 6 allows the `suspend` modifier on all test lifecycle functions. See: https://docs.junit.org/6.0.0/user-guide/index.html#writing-tests-classes-and-methods
JUnit 6 allows the `suspend` modifier on all test lifecycle functions. See: https://docs.junit.org/6.0.0/user-guide/index.html#writing-tests-classes-and-methods
a6faec7 to
79fc736
Compare
stuebingerb
left a comment
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.
Unfortunately, there seems to be an issue with (at least) one of the refactored tests that makes me wonder a bit how reliable runTest really is for certain test cases.
Can you please have a look?
| // syncResolversSchema has 1000 resolvers, each waiting for 3ms. Usually, execution | ||
| // takes about 300ms so if it takes 3s, we apparently ran sequentially. | ||
| duration shouldBeLessThan 3000 | ||
| fun `execution should run in parallel`() = runTest { |
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.
This test now fails to catch the error case it was created for.
In ParallelRequestExecutor, when the extra coroutineScope within plan.toMapAsync is removed, execution in fact no longer runs parallel (as in: the previous test failed because execution time is above 3 seconds):
val resultMap = plan.toMapAsync(dispatcher) {
// coroutineScope {
val ctx = ExecutionContext(this, Variables(variables, it.variables), context, loaders)
if (shouldInclude(ctx, it)) {
writeOperation(
isSubscription = plan.isSubscription,
ctx = ctx,
node = it,
operation = it.field as Field.Function<*, *>
)
} else {
null
}
// }
}
However, the new test still succeeds.
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'm a bit confused right now, because in my current understanding opening a CoroutineScope itself does not change whether something runs async or sync.
So it would have been my expectation that the test still succeeds. Why it changed behaviour with the old one is what I currently do not understand 🤔
Using it has the following benefits over
runBlocking:delay, which is useful to e.g. specify something runs in parallel instead of in sequencerunBlockingwhich are IMO clutter in tests