Skip to content
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 reason to NoAnalysis #2066

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class leakcanary/InstrumentationLeakDetector$Result$AnalysisPerform
}

public final class leakcanary/InstrumentationLeakDetector$Result$NoAnalysis : leakcanary/InstrumentationLeakDetector$Result {
public static final field INSTANCE Lleakcanary/InstrumentationLeakDetector$Result$NoAnalysis;
public fun <init> (Ljava/lang/String;)V
public final fun getReason ()Ljava/lang/String;
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ object TestUtils {
val leakDetector = InstrumentationLeakDetector()

val heapAnalysis = when (val result = leakDetector.detectLeaks()) {
is NoAnalysis -> throw AssertionError("Expected analysis to be performed")
is NoAnalysis -> throw AssertionError(
"Expected analysis to be performed but skipped because ${result.reason}"
)
is AnalysisPerformed -> result.heapAnalysis
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class InstrumentationLeakDetector {
* The result of calling [detectLeaks], which is either [NoAnalysis] or [AnalysisPerformed].
*/
sealed class Result {
object NoAnalysis : Result()
class NoAnalysis(val reason: String) : Result()
class AnalysisPerformed(val heapAnalysis: HeapAnalysis) : Result()
}

Expand All @@ -99,25 +99,25 @@ class InstrumentationLeakDetector {
val refWatcher = AppWatcher.objectWatcher

if (!refWatcher.hasWatchedObjects) {
return NoAnalysis
return NoAnalysis("No watched objects.")
}

instrumentation.waitForIdleSync()
if (!refWatcher.hasWatchedObjects) {
return NoAnalysis
return NoAnalysis("No watched objects after waiting for idle sync.")
}

runGc()
if (!refWatcher.hasWatchedObjects) {
return NoAnalysis
return NoAnalysis("No watched objects after triggering an explicit GC.")
}

// Waiting for any delayed UI post (e.g. scroll) to clear. This shouldn't be needed, but
// Android simply has way too many delayed posts that aren't canceled when views are detached.
SystemClock.sleep(2000)

if (!refWatcher.hasWatchedObjects) {
return NoAnalysis
return NoAnalysis("No watched objects after delayed UI post is cleared.")
}

// Aaand we wait some more.
Expand All @@ -133,7 +133,7 @@ class InstrumentationLeakDetector {
runGc()

if (!refWatcher.hasRetainedObjects) {
return NoAnalysis
return NoAnalysis("No watched objects after a second explicit GC.")
}

// We're always reusing the same file since we only execute this once at a time.
Expand Down