Skip to content

Commit

Permalink
MBS-9422 leftovers for TMS plugin (#571)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dsvoronin committed Sep 14, 2020
1 parent 7283185 commit 500df38
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ internal class MarkReportAsSourceForTMSStepTest {
}
}
tms {
reportsHost = "stub"
}
instrumentation {
sentryDsn = "stub"
slackToken = "stub"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ class TmsPlugin : Plugin<Project> {
target.tasks.register<MarkReportAsSourceTask>(markReportAsSourceTaskName) {
reportsHost.set(extension.reportsHost)
}

target.afterEvaluate {
requireNotNull(extension.reportsHost.orNull) { "tms.reportsHost should be set" }
}
}
}

0 comments on commit 500df38

Please sign in to comment.