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

com.avito.test.summary.FlakyTestInfo.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

import com.avito.android.Result
import com.avito.report.model.SimpleRunTest
import com.avito.report.model.TestName

internal class FlakyTestInfo {

    private val info: MutableList = mutableListOf()

    fun addReport(report: Result>) {
        if (report is Result.Success) {
            extractFlakyInfo(report.getOrThrow()).forEach { newInfo ->
                val oldInfo = info.find { it.testName == newInfo.testName }
                if (oldInfo != null) {
                    info.remove(oldInfo)
                    info.add(
                        oldInfo.copy(
                            attempts = oldInfo.attempts + newInfo.attempts,
                            wastedTimeEstimateInSec = oldInfo.wastedTimeEstimateInSec + newInfo.wastedTimeEstimateInSec
                        )
                    )
                } else {
                    info.add(newInfo)
                }
            }
        }
    }

    fun getInfo(): List = info

    private fun extractFlakyInfo(report: List): List {
        return report.filter { it.lastAttemptDurationInSeconds > 0 }
            .map {
                FlakyInfo(
                    testName = TestName(it.name),
                    attempts = it.stability.attemptsCount,
                    // предположение что проходит тест примерно за одно время, подробнее информации пока нет в api
                    wastedTimeEstimateInSec = it.lastAttemptDurationInSeconds * it.stability.attemptsCount
                )
            }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy