-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make UncompletedTestCoroutines more verbose #3071
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
Make UncompletedTestCoroutines more verbose #3071
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.
Overall looks good
@@ -40,6 +40,7 @@ internal expect suspend inline fun recoverAndThrow(exception: Throwable): Nothin | |||
* The opposite of [recoverStackTrace]. | |||
* It is guaranteed that `unwrap(recoverStackTrace(e)) === e` | |||
*/ | |||
@PublishedApi |
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.
Please leave a comment that it is only used from other module tests, so when the time comes we know it can be safely deleted/reverted
val completionCause = try { | ||
coroutine.tryGetCompletionCause().also { completing = true } | ||
} catch (e: Throwable) { | ||
completing = false |
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.
instead of try-catch
, it should be enough to check coroutine.isCancelled
.
The same goes for completing
throw UncompletedCoroutinesError("The test coroutine was not completed after waiting for $dispatchTimeoutMs ms") | ||
var completing: Boolean | ||
val completionCause = try { | ||
coroutine.tryGetCompletionCause().also { completing = true } |
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.
coroutine.tryGetCompletionCause().also { completing = true } | |
// Protected JobSupport.completionCause lifted in TestCoroutineScope and TestScope | |
coroutine.tryGetCompletionCause().also { completing = true } |
completing = false | ||
null | ||
} | ||
var message = "After waiting for $dispatchTimeoutMs ms" |
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 to follow our overall approach and extract slow-path to a separate method
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.
But this whole code fragment is the slow path, don't you agree?
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.
Agree, then maybe it's worth extracting the whole onTimeout body?
* The error is more verbose: it lists the active children. * If the test coroutine is already finishing with an error, that error is added to the timeout notification as suppressed. * The timeout is considered more important, so now, if there were any uncaught exceptions, they don't take precedence over it but are suppressed by it. Fixes #3066 Fixes #3069
* The error is more verbose: it lists the active children. * If the test coroutine is already finishing with an error, that error is added to the timeout notification as suppressed. * The timeout is considered more important, so now, if there were any uncaught exceptions, they don't take precedence over it but are suppressed by it. Fixes Kotlin#3066 Fixes Kotlin#3069
* The error is more verbose: it lists the active children. * If the test coroutine is already finishing with an error, that error is added to the timeout notification as suppressed. * The timeout is considered more important, so now, if there were any uncaught exceptions, they don't take precedence over it but are suppressed by it. Fixes Kotlin#3066 Fixes Kotlin#3069
Fixes #3066
Fixes #3069