All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avito.test.summary.compose.SlackSummaryComposerImpl.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2022.1
Show newest version
package com.avito.test.summary.compose

import com.avito.android.Result
import com.avito.report.ReportLinkGenerator
import com.avito.report.ReportViewer
import com.avito.report.model.CrossDeviceSuite
import com.avito.report.model.FailureOnDevice
import com.avito.report.model.ReportCoordinates
import com.avito.report.model.Team
import com.avito.slack.SlackStringFormat
import com.avito.test.summary.analysis.analyzeFailures

internal class SlackSummaryComposerImpl(private val reportViewerUrl: String) : SlackSummaryComposer {

    private val insightLimitLength = 400

    override fun composeMessage(
        testData: CrossDeviceSuite,
        team: Team,
        mentionOnFailures: Boolean,
        reportCoordinates: ReportCoordinates,
        reportId: String,
        buildUrl: String
    ): Result {
        val reportLinkGenerator: ReportLinkGenerator = ReportViewer.Impl(reportViewerUrl, reportCoordinates)
        val reportViewerUrl = Result.tryCatch { reportLinkGenerator.generateReportLink(team = team.name) }
        val reportIdentifier = reportCoordinates.runId

        val failures = testData.analyzeFailures()
            .toList()
            .sortedByDescending { it.second.size }
        val topFailures: List>> = failures.take(5)
        val rareFailures = failures.drop(5)
        val rareFailuresCount = rareFailures.sumBy { it.second.size }

        return reportViewerUrl.map { url ->
            StringBuilder().apply {
                appendLine(SlackStringFormat.link(label = "Report: $reportIdentifier", url = url))
                if (team != Team.UNDEFINED) {
                    appendLine("Юнит: ${team.name}\n")
                }
                appendLine("Ручные тесты: ${testData.manualCount}\n")

                appendLine("*Автотесты*: ${testData.automatedCount}")

                // todo адекватная разбивка по flaky
                appendLine(
                    ":green_heart: " +
                        "*Зеленые тесты*: " +
                        "${testData.success} (${testData.percentSuccessOfAutomated})"
                )
                appendLine(
                    ":warning: " +
                        "*Тесты упали только на некоторых девайсах*: " +
                        "${testData.failedOnSomeDevicesCount} (${testData.percentFailedOnSomeDevicesOfAutomated})"
                )
                appendLine(
                    ":red_circle: " +
                        "*Тесты упали на всех девайсах*: " +
                        "${testData.failedOnAllDevicesCount} (${testData.percentFailedOnAllDevicesOfAutomated})"
                )
                appendLine(
                    ":white_circle: " +
                        "*Пропущенные тесты (например, заигнорен) на всех девайсах*: " +
                        "${testData.skippedOnAllDevicesCount} (${testData.percentSkippedOnAllDevicesOfAutomated})"
                )
                appendLine(
                    ":black_circle: " +
                        "*Потерянные тесты (например, зависли и не зарепортились) на некоторых девайсах*: " +
                        "${testData.lostOnSomeDevicesCount} (${testData.percentLostOnSomeDevicesOfAutomated})"
                )

                val hasFailures = testData.failedOnSomeDevicesCount + testData.failedOnAllDevicesCount > 0

                if (mentionOnFailures && hasFailures) {
                    appendLine("${SlackStringFormat.mentionChannel}, т.к. есть упавшие тесты")
                }

                if (topFailures.isNotEmpty()) {
                    appendLine("*Причины падений:*")
                    topFailures.forEach {
                        val reason = SlackStringFormat.ellipsize(string = it.first, limit = insightLimitLength)
                        appendLine("*${it.second.size}* из-за ```$reason```")
                    }
                }

                if (rareFailuresCount > 0) {
                    appendLine("И еще *$rareFailuresCount* более редких падений из-за различных причин.")
                }
            }.toString()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy