Skip to content

Commit

Permalink
MBS-8654 Remove rerun on target branch leftovers (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-krivobokov authored Jul 6, 2020
1 parent a26c987 commit 2c7eb3b
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 166 deletions.
1 change: 0 additions & 1 deletion docs/content/docs/test/Runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ import com.avito.instrumentation.reservation.request.Device.LocalEmulator
instrumentation {
configurations {
local {
tryToReRunOnTargetBranch = false
targets {
api28 {
deviceName = "API28"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@ interface EnvArgs {

}

val isRerunDisabled: Boolean

val build: Build

class Impl(project: Project) : EnvArgs, Serializable {

override val build: Build

override val isRerunDisabled: Boolean =
project.getBooleanProperty("avito.tests.disableRerunOnTargetBranch", default = false)

init {
// todo make local by default?
build = when (project.getOptionalStringProperty("avito.build", "teamcity")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ fun TargetConfiguration.Data.Companion.createStubInstance(
minimumFailedCount = 0
)
),
rerunReservation = Reservation.StaticReservation(
device = Device.CloudEmulator.createStubInstance(),
count = 24,
quota = QuotaConfiguration.Data(
retryCount = 0,
minimumSuccessCount = 1,
minimumFailedCount = 0
)
),
deviceName = deviceName,
instrumentationParams = instrumentationParams
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ fun excludedFilter(reason: TestsFilter.Result.Excluded): TestsFilter {
}

class FakeFilterFactory(
private val initialFilter: TestsFilter = includeAll,
private val rerunFilter: TestsFilter = includeAll
private val filter: TestsFilter = includeAll
) : FilterFactory {

override fun createInitialFilter(): TestsFilter {
return initialFilter
override fun createFilter(): TestsFilter {
return filter
}

override fun createRerunFilter(): TestsFilter {
return rerunFilter
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.io.Serializable
open class TargetConfiguration(val name: String) : Serializable {

lateinit var scheduling: SchedulingConfiguration
var rerunScheduling: SchedulingConfiguration? = null

lateinit var deviceName: String

Expand All @@ -31,21 +30,11 @@ open class TargetConfiguration(val name: String) : Serializable {
}
}

fun rerunScheduling(closure: Closure<SchedulingConfiguration>) {
rerunScheduling = SchedulingConfiguration()
.let {
closure.delegate = it
closure.call()
it
}
}

fun data(parentInstrumentationParameters: InstrumentationParameters): Data {

return Data(
name = name,
reservation = scheduling.data().reservation,
rerunReservation = rerunScheduling?.data()?.reservation ?: scheduling.data().reservation,
deviceName = deviceName,
instrumentationParams = parentInstrumentationParameters
.applyParameters(instrumentationParams)
Expand All @@ -57,14 +46,12 @@ open class TargetConfiguration(val name: String) : Serializable {

fun validate() {
scheduling.validate()
rerunScheduling?.validate()
require(deviceName.isNotBlank()) { "deviceName must be set" }
}

data class Data(
val name: String,
val reservation: Reservation,
val rerunReservation: Reservation,
val deviceName: String,
val instrumentationParams: InstrumentationParameters
) : Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ interface TestExecutor {
logcatDir: File
)

sealed class RunType {
abstract val id: String

data class Run(override val id: String) : RunType()
data class Rerun(override val id: String) : RunType()
}
data class RunType(val id: String)

class Impl(
private val logger: CILogger,
Expand Down Expand Up @@ -66,7 +61,6 @@ interface TestExecutor {
executionParameters = executionParameters
)
val reservations = reservations(
runType,
testsToRun,
configurationName = configuration.name
)
Expand All @@ -77,10 +71,7 @@ interface TestExecutor {
) { devices ->
val testRequests = testsToRun
.map { targetTestRun ->
val reservation = when (runType) {
is RunType.Run -> targetTestRun.target.reservation
is RunType.Rerun -> targetTestRun.target.rerunReservation
}
val reservation = targetTestRun.target.reservation

val quota = reservation.quota

Expand Down Expand Up @@ -140,18 +131,14 @@ interface TestExecutor {
).apply { mkdirs() }

private fun reservations(
runType: RunType,
tests: List<TestWithTarget>,
configurationName: String
): Collection<Reservation.Data> {

val testsGroupedByTargets: Map<TargetGroup, List<TestWithTarget>> = tests.groupBy {
TargetGroup(
name = it.target.name,
reservation = when (runType) {
is RunType.Run -> it.target.reservation
is RunType.Rerun -> it.target.rerunReservation
}
reservation = it.target.reservation
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ interface InstrumentationTestActionFinalizer {
testsExecutionResults: TestsScheduler.Result
) {
val testRunResult = TestRunResult(
reportedTests = testsExecutionResults.initialTestsResult.getOrElse { emptyList() },
reportedTests = testsExecutionResults.testsResult.getOrElse { emptyList() },
failed = hasFailedTestDeterminer.determine(
runResult = testsExecutionResults.testResultsAfterBranchReruns
runResult = testsExecutionResults.testsResult
),
notReported = hasNotReportedTestsDeterminer.determine(
runResult = testsExecutionResults.initialTestsResult,
allTests = testsExecutionResults.initialTestSuite.testsToRun.map { it.test }
runResult = testsExecutionResults.testsResult,
allTests = testsExecutionResults.testSuite.testsToRun.map { it.test }
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,35 @@ class InstrumentationTestsScheduler(

val flakyTestInfo = FlakyTestInfo()

val initialTestSuite = testSuiteProvider.getInitialTestSuite(
val testSuite = testSuiteProvider.getTestSuite(
tests = testSuiteLoader.loadTestSuite(params.testApk, AllChecks())
)

filterInfoWriter.writeAppliedFilter(initialTestSuite.appliedFilter)
filterInfoWriter.writeFilterExcludes(initialTestSuite.skippedTests)
filterInfoWriter.writeAppliedFilter(testSuite.appliedFilter)
filterInfoWriter.writeFilterExcludes(testSuite.skippedTests)

writeInitialTestSuite(initialTestSuite)
writeTestSuite(testSuite)

val initialTestsResult = testsRunner.runTests(
val testsResult = testsRunner.runTests(
mainApk = params.mainApk,
testApk = params.testApk,
runType = TestExecutor.RunType.Run(id = "initialRun"),
runType = TestExecutor.RunType(id = "initialRun"),
reportCoordinates = reportCoordinates,
report = sourceReport,
testsToRun = initialTestSuite.testsToRun
testsToRun = testSuite.testsToRun
)

flakyTestInfo.addReport(initialTestsResult)
flakyTestInfo.addReport(testsResult)

return TestsScheduler.Result(
initialTestSuite = initialTestSuite,
initialTestsResult = initialTestsResult,
testResultsAfterBranchReruns = initialTestsResult,
testSuite = testSuite,
testsResult = testsResult,
flakyInfo = flakyTestInfo.getInfo()
)
}

private fun writeInitialTestSuite(initialTestSuite: TestSuiteProvider.TestSuite) {
File(params.outputDir, "initial-suite.json")
.writeText(gson.toJson(initialTestSuite.testsToRun.map { it.test }))
private fun writeTestSuite(testSuite: TestSuiteProvider.TestSuite) {
File(params.outputDir, "test-suite.json")
.writeText(gson.toJson(testSuite.testsToRun.map { it.test }))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ interface TestsScheduler {
fun schedule(): Result

data class Result(
val initialTestSuite: TestSuiteProvider.TestSuite,
val initialTestsResult: Try<List<SimpleRunTest>>,
val testResultsAfterBranchReruns: Try<List<SimpleRunTest>>,
val testSuite: TestSuiteProvider.TestSuite,
val testsResult: Try<List<SimpleRunTest>>,
val flakyInfo: List<FlakyInfo>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ interface TestSuiteProvider {
val skippedTests: List<Pair<TestWithTarget, Excluded>>
)

fun getInitialTestSuite(tests: List<TestInApk>): TestSuite
fun getRerunTestsSuite(tests: List<TestInApk>): TestSuite
fun getTestSuite(tests: List<TestInApk>): TestSuite

class Impl(
private val report: Report,
Expand All @@ -31,14 +30,13 @@ interface TestSuiteProvider {
private val filterFactory: FilterFactory
) : TestSuiteProvider {


override fun getInitialTestSuite(
override fun getTestSuite(
tests: List<TestInApk>
): TestSuite {

val suite = getTestSuite(
tests = tests,
filter = filterFactory.createInitialFilter()
filter = filterFactory.createFilter()
)

if (reportSkippedTests) {
Expand All @@ -62,13 +60,6 @@ interface TestSuiteProvider {
return suite
}

override fun getRerunTestsSuite(
tests: List<TestInApk>
): TestSuite = getTestSuite(
tests = tests,
filter = filterFactory.createRerunFilter()
)

private fun getTestSuite(
tests: List<TestInApk>,
filter: TestsFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import com.avito.report.model.SimpleRunTest
import java.io.File

interface FilterFactory {
fun createInitialFilter(): TestsFilter
fun createRerunFilter(): TestsFilter
fun createFilter(): TestsFilter

companion object {
internal val JUNIT_IGNORE_ANNOTATION = "org.junit.Ignore"
internal const val JUNIT_IGNORE_ANNOTATION = "org.junit.Ignore"

fun create(
filterData: InstrumentationFilter.Data,
Expand All @@ -37,7 +36,7 @@ private class FilterFactoryImpl(
private val reportConfig: Report.Factory.Config
) : FilterFactory {

override fun createInitialFilter(): TestsFilter {
override fun createFilter(): TestsFilter {
val filters = mutableListOf<TestsFilter>()
filters.add(ExcludeBySdkFilter())
filters.addAnnotationFilters()
Expand All @@ -50,14 +49,6 @@ private class FilterFactoryImpl(
)
}

override fun createRerunFilter(): TestsFilter {
val filters = mutableListOf<TestsFilter>()
filters.addSourcePreviousSignatureFilters()
return CompositionFilter(
filters
)
}

private fun MutableList<TestsFilter>.addAnnotationFilters() {
if (filterData.fromSource.annotations.included.isNotEmpty()) {
add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ internal class InstrumentationTestsActionIntegrationTest {
private val reportsApi = FakeReportsApi()
private val testSuiteLoader = FakeTestSuiteLoader()
private val reportCoordinates = ReportCoordinates.createStubInstance()
private val targetReportCoordinates =
reportCoordinates.copy(jobSlug = reportCoordinates.jobSlug + "-rerun")
private val testRunner = FakeTestExecutor()
private val testExecutorFactory = object : TestExecutorFactory {
override fun createExecutor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,24 @@ internal class TestSuiteProviderTest {
)

@Test
fun `initial suite - dont skip tests - if rerun enabled, but results unavailable`() {
fun `test suite - dont skip tests`() {
val testSuiteProvider = createTestSuiteProvider()

val result = testSuiteProvider.getInitialTestSuite(
val result = testSuiteProvider.getTestSuite(
tests = listOf(simpleTestInApk)
)

assertThat(result.testsToRun.map { it.test.name }).containsExactly(simpleTestInApk.testName)
}

@Test
fun `initial suite - dont skip tests - if rerun enabled, but report is empty`() {
val testSuiteProvider = createTestSuiteProvider()

val result = testSuiteProvider.getInitialTestSuite(
tests = listOf(simpleTestInApk)
)

assertThat(result.testsToRun.map { it.test.name }).containsExactly(simpleTestInApk.testName)
}

@Test
fun `initial suite - dont skip tests - if rerun enabled, but previous report does not contain specific test`() {
val testSuiteProvider = createTestSuiteProvider()

val result = testSuiteProvider.getInitialTestSuite(
tests = listOf(simpleTestInApk)
)

assertThat(result.testsToRun.map { it.test.name }).containsExactly(simpleTestInApk.testName)
}

@Test
fun `initial suite - skip test - if rerun enabled and test passed in previous run`() {
fun `test suite - skip test - if rerun enabled and test passed in previous run`() {
val report = FakeReport()
val testSuiteProvider = createTestSuiteProvider(
report = report,
reportSkippedTests = true,
filterFactory = FakeFilterFactory(
initialFilter = excludedFilter(
filter = excludedFilter(
TestsFilter.Result.Excluded.MatchExcludeSignature(
name = "",
source = TestsFilter.Signatures.Source.PreviousRun
Expand All @@ -70,7 +48,7 @@ internal class TestSuiteProviderTest {
)
)

testSuiteProvider.getInitialTestSuite(
testSuiteProvider.getTestSuite(
tests = listOf(simpleTestInApk)
)

Expand Down
Loading

0 comments on commit 2c7eb3b

Please sign in to comment.