-
Notifications
You must be signed in to change notification settings - Fork 101
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
wrap Activity and Compose rules in LeakCanary checks on both sides #658
base: main
Are you sure you want to change the base?
Conversation
* | ||
* https://github.com/square/workflow-kotlin/issues/657 | ||
*/ | ||
public fun TestRule.wrapInLeakCanary(): RuleChain = requireNotNull( |
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.
The actual rule is just above the fold, so GitHub won't let me comment on the line I'm interested in...
Lines 29 to 36 in 72ba8c7
try { | |
base.evaluate() | |
LeakAssertions.assertNoLeaks(tag) | |
} finally { | |
// Otherwise upstream test failures will be reported as leaks. | |
// https://github.com/square/leakcanary/issues/2297 | |
AppWatcher.objectWatcher.clearWatchedObjects() | |
} |
If we're executing this twice per test, do we want to skip the call to clearWatchedObjects()
the first time?
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 have no idea. @py?
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.
No, should be fine. But maybe use clearAfter timestamp instead
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.
try {
base.evaluate()
val heapDumpUptimeMillis = SystemClock.uptimeMillis()
LeakAssertions.assertNoLeaks(tag)
} finally {
// Otherwise upstream test failures will be reported as leaks.
// https://github.com/square/leakcanary/issues/2297
AppWatcher.objectWatcher.clearObjectsWatchedBefore(heapDumpUptimeMillis)
}
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 made this change -- thanks!
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.
LGTM
But I'm just learning about all this, so you probably want another 👍
6a94bf3
to
dd7b12a
Compare
dd7b12a
to
5b404c2
Compare
One thing to note: all the changes here (and in internal forks of the rule) have been backported to LeakCanary which will soon be released as 2.9. You'll need to adapt the code a bit but should be able to delete this custom rule. |
@RBusarow Any plans to update this to LC 2.9 and get it merged? |
Yeah, I'll get this updated soon. I took a stab at it a while ago and was running into leaks in the compose activity rule, but didn't have the time to dig into it. |
I'm open to bike-shedding the name. 😄
fixes #657