Skip to content

Commit

Permalink
MBS-10890 Add main looper messages log to the test report (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
sboishtyan authored Mar 25, 2021
1 parent a162a65 commit 7b6e591
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.avito.android.runner.annotation.resolver.TestMethodOrClass
import com.avito.android.runner.annotation.resolver.getTestOrThrow
import com.avito.android.runner.annotation.validation.CompositeTestMetadataValidator
import com.avito.android.runner.annotation.validation.TestMetadataValidator
import com.avito.android.runner.delegates.MainLooperMessagesLogDelegate
import com.avito.android.runner.delegates.ReportLifecycleEventsDelegate
import com.avito.android.sentry.SentryConfig
import com.avito.android.test.UITestConfig
Expand All @@ -30,6 +31,8 @@ import com.avito.android.test.report.model.TestMetadata
import com.avito.android.test.report.transport.ExternalStorageTransport
import com.avito.android.test.report.transport.LocalRunTransport
import com.avito.android.test.report.transport.Transport
import com.avito.android.test.report.troubleshooting.Troubleshooter
import com.avito.android.test.report.troubleshooting.dump.MainLooperMessagesLogDumper
import com.avito.android.test.report.video.VideoCaptureTestListener
import com.avito.android.util.DeviceSettingsChecker
import com.avito.android.util.ImitateFlagProvider
Expand Down Expand Up @@ -63,6 +66,8 @@ abstract class InHouseInstrumentationTestRunner :

private val timeProvider: TimeProvider by lazy { DefaultTimeProvider() }

private val mainLooperMessagesLogDumper by lazy { MainLooperMessagesLogDumper() }

/**
* Public for *TestApp to skip on orchestrator runs
*/
Expand Down Expand Up @@ -135,7 +140,8 @@ abstract class InHouseInstrumentationTestRunner :
transport = transport,
loggerFactory = loggerFactory,
remoteStorage = remoteStorage,
timeProvider = timeProvider
timeProvider = timeProvider,
troubleshooter = Troubleshooter.Impl(mainLooperMessagesLogDumper)
)
}

Expand Down Expand Up @@ -179,7 +185,8 @@ abstract class InHouseInstrumentationTestRunner :

override fun getDelegates(arguments: Bundle): List<InstrumentationTestRunnerDelegate> {
return listOf(
ReportLifecycleEventsDelegate(report)
ReportLifecycleEventsDelegate(report),
MainLooperMessagesLogDelegate(mainLooperMessagesLogDumper)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.avito.android.runner.delegates

import android.os.Bundle
import com.avito.android.runner.InstrumentationTestRunnerDelegate
import com.avito.android.test.report.troubleshooting.dump.MainLooperMessagesLogDumper

class MainLooperMessagesLogDelegate(
private val dumper: MainLooperMessagesLogDumper
) : InstrumentationTestRunnerDelegate() {

override fun beforeOnStart() {
dumper.start()
}

override fun beforeFinish(resultCode: Int, results: Bundle?) {
dumper.stop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ReportImplementation(
loggerFactory = loggerFactory
),
private val timeProvider: TimeProvider,
private val troubleshooter: Troubleshooter = Troubleshooter.Impl
private val troubleshooter: Troubleshooter
) : Report,
StepLifecycleListener by StepLifecycleNotifier,
TestLifecycleListener by TestLifecycleNotifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.avito.android.test.report.troubleshooting

import com.avito.android.test.report.Report
import com.avito.android.test.report.troubleshooting.dump.MainLooperDumper
import com.avito.android.test.report.troubleshooting.dump.MainLooperMessagesLogDumper
import com.avito.android.test.report.troubleshooting.dump.MainLooperQueueDumper
import com.avito.android.test.report.troubleshooting.dump.ThreadDumper
import com.avito.android.test.report.troubleshooting.dump.ViewHierarchyDumper

interface Troubleshooter {

fun troubleshootTo(report: Report)

object Impl : Troubleshooter {
class Impl(
private val mainLooperMessagesLogDumper: MainLooperMessagesLogDumper
) : Troubleshooter {

override fun troubleshootTo(report: Report) {
with(report) {
addText("Threads dump", ThreadDumper.getThreadDump())
addText("Main looper dump", MainLooperDumper.getDump())
addText("Main looper processed messages dump", mainLooperMessagesLogDumper.getMessagesLogDump())
addText("Main looper queue dump", MainLooperQueueDumper.getDump())
addText("View hierarchy dump", ViewHierarchyDumper.getDump())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.avito.android.test.report.troubleshooting.dump

import android.os.Looper
import android.util.Printer

class MainLooperMessagesLogDumper : Printer {

private val logs = StringBuilder()

init {
Looper.getMainLooper().setMessageLogging(this)
}

override fun println(log: String) {
logs.appendLine(log)
}

fun getMessagesLogDump(): String {
return logs.toString()
}

fun start() {
logs.clear() // if we run a few tests with one instrumentation instance
Looper.getMainLooper().setMessageLogging(this)
}

fun stop() {
Looper.getMainLooper().setMessageLogging(null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.avito.android.test.report.troubleshooting.dump

import android.os.Looper

object MainLooperDumper {
object MainLooperQueueDumper {

fun getDump(): String {
val dump = StringBuilder()
Expand Down

0 comments on commit 7b6e591

Please sign in to comment.