From 500df384720be53977af85ed90b69bfec94054e1 Mon Sep 17 00:00:00 2001 From: Dmitriy Voronin Date: Mon, 14 Sep 2020 15:00:45 +0300 Subject: [PATCH] MBS-9422 leftovers for TMS plugin (#571) * MBS-9422 leftovers for TMS plugin - failfast at configuration time if no reportHost provided - rewrite log messages to clearly understand state * MBS-9422 fix test --- .../steps/MarkReportAsSourceForTMSStepTest.kt | 4 ++ .../avito/plugin/MarkReportAsSourceAction.kt | 58 ++++++++++--------- .../main/kotlin/com/avito/plugin/TmsPlugin.kt | 4 ++ 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt index 9c8859e19b..520927a977 100644 --- a/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt +++ b/subprojects/gradle/cd/src/test/kotlin/com/avito/ci/steps/MarkReportAsSourceForTMSStepTest.kt @@ -31,6 +31,10 @@ internal class MarkReportAsSourceForTMSStepTest { } } + tms { + reportsHost = "stub" + } + instrumentation { sentryDsn = "stub" slackToken = "stub" diff --git a/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/MarkReportAsSourceAction.kt b/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/MarkReportAsSourceAction.kt index 071eccc37e..a47e1aea1a 100644 --- a/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/MarkReportAsSourceAction.kt +++ b/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/MarkReportAsSourceAction.kt @@ -19,42 +19,46 @@ class MarkReportAsSourceAction( private val timeProvider: TimeProvider, private val logger: Logger ) { + private val tag = "TMS" fun mark(reportCoordinates: ReportCoordinates) { val testSuiteVersion = timeProvider.nowInMillis() - logger.debug("This is a new version [$testSuiteVersion] of full test suite for tms") + when (val result = reportsApi.getReport(reportCoordinates)) { + is GetReportResult.Found -> { - val reportId = tryGetId(reportCoordinates) - - if (reportId != null) { - reportsApi.pushPreparedData( - reportId = reportId, - analyzerKey = "test_suite", - preparedData = jsonObject( - "full" to true, - "version" to testSuiteVersion - ) - ).onFailure { error -> - logger.critical("Can't push prepared data: testSuite info", error) - } - - reportsApi.setFinished(reportCoordinates).onFailure { error -> - logger.critical("Can't finish report for coordinates: $reportCoordinates", error) + reportsApi.pushPreparedData( + reportId = result.report.id, + analyzerKey = "test_suite", + preparedData = jsonObject( + "full" to true, + "version" to testSuiteVersion + ) + ).fold( + { + reportsApi.setFinished(reportCoordinates).fold( + { + logger.info( + "[$tag] Test suite for tms version $testSuiteVersion, " + + "with id: ${result.report.id}, coordinates: $reportCoordinates marked as source of truth for tms" + ) + }, + { error -> + logger.critical("[$tag] Can't finish report for coordinates: $reportCoordinates", error) + }) + }, + { error -> + logger.critical("[$tag] Can't push prepared data: testSuite info", error) + }) } - } - } - - private fun tryGetId(reportCoordinates: ReportCoordinates): String? { - return when (val result = reportsApi.getReport(reportCoordinates)) { - is GetReportResult.Found -> result.report.id GetReportResult.NotFound -> { - logger.warn("Can't find report for runId=${reportCoordinates.runId}") - null + logger.critical( + "[$tag] Can't get reportId for coordinates: $reportCoordinates", + IllegalStateException("stub") + ) } is GetReportResult.Error -> { - logger.critical("Can't find report for runId=${reportCoordinates.runId}", result.exception) - null + logger.critical("[$tag] Can't find report for runId=${reportCoordinates.runId}", result.exception) } } } diff --git a/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/TmsPlugin.kt b/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/TmsPlugin.kt index 0bcb72b8c5..408a28207a 100644 --- a/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/TmsPlugin.kt +++ b/subprojects/gradle/tms/src/main/kotlin/com/avito/plugin/TmsPlugin.kt @@ -13,5 +13,9 @@ class TmsPlugin : Plugin { target.tasks.register(markReportAsSourceTaskName) { reportsHost.set(extension.reportsHost) } + + target.afterEvaluate { + requireNotNull(extension.reportsHost.orNull) { "tms.reportsHost should be set" } + } } }