Skip to content

Commit

Permalink
Mbs 9655 Extract test summary logic from runner (#587)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Boishtyan <ssboishtyan@avito.ru>
  • Loading branch information
dsvoronin and sboishtyan authored Oct 5, 2020
1 parent e2addaa commit 53fe9d9
Show file tree
Hide file tree
Showing 44 changed files with 685 additions and 357 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ infra?=
ci?=false
log_level?=-q
kubernetesContext?=beta
localFilter?=
testFilter?=
includePrefix?=
includeAnnotation?=
useCompositeBuild=true
Expand All @@ -12,8 +12,8 @@ instrumentation=Ui

params?=

ifdef localFilter
params +=-PlocalFilter=$(localFilter)
ifdef testFilter
params +=-PcustomFilter=$(testFilter)
endif

ifdef includePrefix
Expand Down
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ subprojects {
}
}

filters.register("ci") {
fromSource.excludeFlaky = true
}

val defaultFilter = "default"
val customFilter: String = project.getOptionalStringProperty("localFilter", defaultFilter)
val customFilter: String = project.getOptionalStringProperty("customFilter", defaultFilter)

configurationsContainer.register("Local") {
reportSkippedTests = true
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ runInBuilder "set -e;
./gradlew help;
./gradlew help -PuseCompositeBuild=false;
./gradlew -p subprojects build ${GRADLE_ARGS};
./gradlew :samples:test-app:instrumentationUi :samples:test-app-without-backward-compatibility:instrumentationUi :samples:test-app-screenshot-test:instrumentationScreenshot ${GRADLE_ARGS}"
./gradlew :samples:test-app:instrumentationUi :samples:test-app-without-backward-compatibility:instrumentationUi :samples:test-app-screenshot-test:instrumentationScreenshot -PcustomFilter=ci ${GRADLE_ARGS}"
29 changes: 15 additions & 14 deletions subprojects/gradle/cd/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@ plugins {
dependencies {
implementation(gradleApi())
implementation(Dependencies.funktionaleTry)
implementation(project(":common:report-viewer"))
implementation(project(":gradle:android"))
implementation(project(":gradle:impact-shared"))
implementation(project(":gradle:impact"))
implementation(project(":gradle:kotlin-dsl-support"))
implementation(project(":gradle:utils"))
implementation(project(":gradle:artifactory-app-backup"))
implementation(project(":gradle:ci-logger"))
implementation(project(":gradle:signer"))
implementation(project(":gradle:files"))
implementation(project(":gradle:lint-report"))
implementation(project(":gradle:git"))
implementation(project(":gradle:impact"))
implementation(project(":gradle:impact-shared"))
implementation(project(":gradle:instrumentation-tests"))
implementation(project(":gradle:artifactory-app-backup"))
implementation(project(":gradle:kotlin-dsl-support"))
implementation(project(":gradle:lint-report"))
implementation(project(":gradle:prosector"))
implementation(project(":gradle:qapps"))
implementation(project(":gradle:tms"))
implementation(project(":gradle:signer"))
implementation(project(":gradle:teamcity"))
implementation(project(":gradle:prosector"))
implementation(project(":gradle:git"))
implementation(project(":gradle:test-summary"))
implementation(project(":gradle:tms"))
implementation(project(":gradle:upload-cd-build-result"))
implementation(project(":gradle:upload-to-googleplay"))
implementation(project(":common:report-viewer"))
implementation(project(":gradle:utils"))

testImplementation(project(":gradle:test-project"))
testImplementation(project(":gradle:impact-shared-test-fixtures"))
testImplementation(project(":gradle:artifactory-app-backup-test-fixtures"))
testImplementation(project(":common:test-okhttp"))
testImplementation(project(":gradle:artifactory-app-backup-test-fixtures"))
testImplementation(project(":gradle:impact-shared-test-fixtures"))
testImplementation(project(":gradle:test-project"))
}

configurations.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import com.avito.ci.steps.BuildStep
import com.avito.ci.steps.CompileUiTests
import com.avito.ci.steps.ConfigurationCheck
import com.avito.ci.steps.DeployStep
import com.avito.ci.steps.FlakyReportStep
import com.avito.ci.steps.ImpactAnalysisAwareBuildStep
import com.avito.ci.steps.LintCheck
import com.avito.ci.steps.MarkReportAsSourceForTMSStep
import com.avito.ci.steps.TestSummaryStep
import com.avito.ci.steps.UiTestCheck
import com.avito.ci.steps.UnitTestCheck
import com.avito.ci.steps.UploadBuildResult
Expand Down Expand Up @@ -50,6 +52,12 @@ open class BuildStepListExtension(
registerFactory(MarkReportAsSourceForTMSStep::class.java) { name ->
MarkReportAsSourceForTMSStep(buildStepListName, name)
}
registerFactory(TestSummaryStep::class.java) { name ->
TestSummaryStep(buildStepListName, name)
}
registerFactory(FlakyReportStep::class.java) { name ->
FlakyReportStep(buildStepListName, name)
}
registerFactory(UploadToQapps::class.java) { name ->
UploadToQapps(buildStepListName, artifactsConfig, name)
}
Expand Down Expand Up @@ -123,6 +131,22 @@ open class BuildStepListExtension(
configureAndAdd("markReportAsSourceForTMS", action)
}

fun testSummary(closure: Closure<TestSummaryStep>) {
configureAndAdd("testSummary", closure)
}

fun testSummary(action: Action<TestSummaryStep>) {
configureAndAdd("testSummary", action)
}

fun flakyReport(closure: Closure<FlakyReportStep>) {
configureAndAdd("flakyReport", closure)
}

fun flakyReport(action: Action<FlakyReportStep>) {
configureAndAdd("flakyReport", action)
}

fun uploadToQapps(closure: Closure<UploadToQapps>) {
configureAndAdd("uploadToQapps", closure)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.avito.ci.steps

import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.avito.impact.configuration.internalModule
import com.avito.instrumentation.extractReportCoordinates
import com.avito.instrumentation.instrumentationTask
import com.avito.test.summary.flakyReportTask
import com.avito.test.summary.testSummaryPluginId
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider

class FlakyReportStep(context: String, name: String) : SuppressibleBuildStep(context, name),
ImpactAnalysisAwareBuildStep by ImpactAnalysisAwareBuildStep.Impl() {

var configuration: String = ""

override fun registerTask(project: Project, rootTask: TaskProvider<out Task>) {
require(project.pluginManager.hasPlugin(testSummaryPluginId)) {
"FlakyReport step can't be initialized without $testSummaryPluginId plugin applied"
}

require(configuration.isNotBlank()) {
"FlakyReport step can't be initialized without provided instrumentation configuration"
}

if (useImpactAnalysis && !project.internalModule.isModified()) return

val instrumentationTask = project.tasks.instrumentationTask(configuration)

val flakyReportTask = project.tasks.flakyReportTask()
flakyReportTask.configure {
it.dependsOn(instrumentationTask)
it.reportCoordinates.set(instrumentationTask.extractReportCoordinates())
}
rootTask.dependsOn(flakyReportTask)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.avito.ci.steps

import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.avito.impact.configuration.internalModule
import com.avito.instrumentation.extractReportCoordinates
import com.avito.instrumentation.instrumentationTask
import com.avito.test.summary.testSummaryPluginId
import com.avito.test.summary.testSummaryTask
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider

class TestSummaryStep(context: String, name: String) : SuppressibleBuildStep(context, name),
ImpactAnalysisAwareBuildStep by ImpactAnalysisAwareBuildStep.Impl() {

var configuration: String = ""

override fun registerTask(project: Project, rootTask: TaskProvider<out Task>) {
require(project.pluginManager.hasPlugin(testSummaryPluginId)) {
"TestSummary step can't be initialized without $testSummaryPluginId plugin applied"
}

require(configuration.isNotBlank()) {
"TestSummary step can't be initialized without provided instrumentation configuration"
}

if (useImpactAnalysis && !project.internalModule.isModified()) return

val instrumentationTask = project.tasks.instrumentationTask(configuration)

val testSummaryTask = project.tasks.testSummaryTask()
testSummaryTask.configure {
it.dependsOn(instrumentationTask)
it.reportCoordinates.set(instrumentationTask.extractReportCoordinates())
}
rootTask.dependsOn(testSummaryTask)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ open class UiTestCheck(context: String, name: String) : SuppressibleBuildStep(co

var configurations = mutableListOf<String>()

/**
* нам пока нужна отправка только по запуску на всех устройствах
*/
@Deprecated("remove after 2020.23")
var sendStatistics: Boolean = false

fun configurations(vararg configs: String) {
Expand Down Expand Up @@ -55,6 +53,8 @@ open class UiTestCheck(context: String, name: String) : SuppressibleBuildStep(co
uiTestTask.get().also { task ->
task.suppressFailure.set(this@UiTestCheck.suppressFailures)
task.suppressFlaky.set(this@UiTestCheck.suppressFlaky)

//todo remove after 2020.23
task.sendStatistics.set(this@UiTestCheck.sendStatistics)

// TODO: how to switch off impact analysis?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.avito.ci.steps

import com.avito.test.gradle.TestProjectGenerator
import com.avito.test.gradle.ciRun
import com.avito.test.gradle.module.AndroidAppModule
import com.avito.test.summary.testSummaryExtensionName
import com.avito.test.summary.testSummaryPluginId
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import java.io.File

internal class TestSummaryStepTest {

@Test
fun testSummary(@TempDir projectDir: File) {
generateProject(
projectDir,
"""
testSummary {
configuration = "ui"
}
""".trimIndent()
)

ciRun(
projectDir,
"fullCheck",
dryRun = true
)
.assertThat()
.buildSuccessful()
.tasksShouldBeTriggered(
":app:instrumentationUi",
":app:testSummary",
":app:fullCheck"
)
.inOrder()
}

@Test
fun flakyReport(@TempDir projectDir: File) {
generateProject(
projectDir,
"""
flakyReport {
configuration = "ui"
}
""".trimIndent()
)

ciRun(
projectDir,
"fullCheck",
dryRun = true
)
.assertThat()
.buildSuccessful()
.tasksShouldBeTriggered(
":app:instrumentationUi",
":app:flakyReport",
":app:fullCheck"
)
.inOrder()
}

private fun generateProject(projectDir: File, step: String) {
TestProjectGenerator(
plugins = listOf("com.avito.android.impact"),
modules = listOf(
AndroidAppModule(
name = "app",
plugins = listOf(
testSummaryPluginId,
"com.avito.android.instrumentation-tests",
"com.avito.android.cd"
),
buildGradleExtra = """
import static com.avito.instrumentation.reservation.request.Device.LocalEmulator
android {
defaultConfig {
testInstrumentationRunner = "no_matter"
}
}
$testSummaryExtensionName {
reportsHost = "stub"
}
instrumentation {
sentryDsn = "stub"
slackToken = "stub"
registry = "stub"
configurations {
ui {
targets {
api29 {
deviceName = "api29"
scheduling {
quota {
minimumSuccessCount = 1
}
staticDevicesReservation {
device = LocalEmulator.device(27)
count = 1
}
}
}
}
}
}
}
builds {
fullCheck {
$step
}
}
""".trimIndent()
)
)
).generateIn(projectDir)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fun InstrumentationConfiguration.Data.Companion.createStubInstance(
name: String = "name",
instrumentationParams: InstrumentationParameters = InstrumentationParameters(),
reportSkippedTests: Boolean = true,
reportFlakyTests: Boolean = false,
impactAnalysisPolicy: ImpactAnalysisPolicy = ImpactAnalysisPolicy.Off,
kubernetesNamespace: String = "kubernetesNamespace",
targets: List<TargetConfiguration.Data> = emptyList(),
Expand All @@ -22,7 +21,6 @@ fun InstrumentationConfiguration.Data.Companion.createStubInstance(
): InstrumentationConfiguration.Data = InstrumentationConfiguration.Data(
name = name,
instrumentationParams = instrumentationParams,
reportFlakyTests = reportFlakyTests,
reportSkippedTests = reportSkippedTests,
impactAnalysisPolicy = impactAnalysisPolicy,
kubernetesNamespace = kubernetesNamespace,
Expand Down
Loading

0 comments on commit 53fe9d9

Please sign in to comment.