From 9e1443ed6dc1a100749c3b0e3c0817da901a4f5a Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 17:09:49 +0300 Subject: [PATCH] Don't recalculate counters in Execution if value is `NOT_APPLICABLE` (#1170) * Store aggregated metrics in Execution excluding `NOT_APPLICABLE` metrics from individual test executions (until we can calculate scores for other types of plugins too) * Change logic of dispaly on frontend: don't calculate metrics only if all test executions under an execution are `NOT_APPLICABLE`; otherwise use filtered data from Execution Related to #1115 Co-authored-by: Nariman Abdullin --- .../backend/service/TestExecutionService.kt | 24 ++++++++++++------- .../components/basic/ExecutionLabels.kt | 15 ++---------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/TestExecutionService.kt b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/TestExecutionService.kt index 973153da6d..cfaa28e1f2 100644 --- a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/TestExecutionService.kt +++ b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/TestExecutionService.kt @@ -6,6 +6,7 @@ import com.saveourtool.save.backend.repository.ExecutionRepository import com.saveourtool.save.backend.repository.TestExecutionRepository import com.saveourtool.save.backend.repository.TestRepository import com.saveourtool.save.backend.utils.secondsToLocalDateTime +import com.saveourtool.save.core.result.CountWarnings import com.saveourtool.save.domain.TestResultLocation import com.saveourtool.save.domain.TestResultStatus import com.saveourtool.save.entities.Execution @@ -16,7 +17,6 @@ import com.saveourtool.save.test.TestDto import com.saveourtool.save.utils.ScoreType import com.saveourtool.save.utils.calculateScore import com.saveourtool.save.utils.debug -import com.saveourtool.save.utils.error import com.saveourtool.save.utils.getLogger import org.apache.commons.io.FilenameUtils @@ -167,10 +167,11 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep "LongMethod", "MAGIC_NUMBER", "MagicNumber", + "PARAMETER_NAME_IN_OUTER_LAMBDA", ) @Transactional fun saveTestResult(testExecutionsDtos: List): List { - log.debug("Saving ${testExecutionsDtos.size} test results from agent ${testExecutionsDtos.first().agentContainerId}") + log.debug { "Saving ${testExecutionsDtos.size} test results from agent ${testExecutionsDtos.first().agentContainerId}" } // we take agent id only from first element, because all test executions have same execution val agentContainerId = requireNotNull(testExecutionsDtos.first().agentContainerId) { "Attempt to save test results without assigned agent. testExecutionDtos=$testExecutionsDtos" @@ -212,10 +213,12 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep it.expected = testExecDto.expected it.unexpected = testExecDto.unexpected - counters.unmatchedChecks += testExecDto.unmatched ?: 0L - counters.matchedChecks += testExecDto.matched ?: 0L - counters.expectedChecks += testExecDto.expected ?: 0L - counters.unexpectedChecks += testExecDto.unexpected ?: 0L + with(counters) { + unmatchedChecks += testExecDto.unmatched.orZeroIfNotApplicable() + matchedChecks += testExecDto.matched.orZeroIfNotApplicable() + expectedChecks += testExecDto.expected.orZeroIfNotApplicable() + unexpectedChecks += testExecDto.unexpected.orZeroIfNotApplicable() + } testExecutionRepository.save(it) }, @@ -229,9 +232,10 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep transactionTemplate.execute { val execution = executionRepository.findById(executionId).get() execution.apply { - log.debug("Updating counters in execution id=$executionId: running=$runningTests-${counters.total()}, " + - "passed=$passedTests+${counters.passed}, failed=$failedTests+${counters.failed}, skipped=$skippedTests+${counters.skipped}" - ) + log.debug { + "Updating counters in execution id=$executionId: running=$runningTests-${counters.total()}, " + + "passed=$passedTests+${counters.passed}, failed=$failedTests+${counters.failed}, skipped=$skippedTests+${counters.skipped}" + } runningTests -= counters.total() passedTests += counters.passed failedTests += counters.failed @@ -352,6 +356,8 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep } } + private fun Long?.orZeroIfNotApplicable() = this?.takeUnless { CountWarnings.isNotApplicable(it.toInt()) } ?: 0 + @Suppress( "KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_ON_FUNCTION", diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/ExecutionLabels.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/ExecutionLabels.kt index f75288434e..17432f95b3 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/ExecutionLabels.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/ExecutionLabels.kt @@ -7,7 +7,6 @@ package com.saveourtool.save.frontend.components.basic -import com.saveourtool.save.core.result.CountWarnings import com.saveourtool.save.execution.ExecutionDto import com.saveourtool.save.execution.ExecutionStatus import com.saveourtool.save.frontend.externals.fontawesome.faRedo @@ -101,25 +100,15 @@ internal class ExecutionStatisticsValues(executionDto: ExecutionDto?) { ?: "0" this.precisionRate = executionDto ?.let { - if (isAllApplicable(it.matchedChecks, it.unexpectedChecks)) { - "${it.getPrecisionRate()}" - } else { - "N/A" - } + "${it.getPrecisionRate()}" } ?: "0" this.recallRate = executionDto ?.let { - if (isAllApplicable(it.matchedChecks, it.unmatchedChecks)) { - "${it.getRecallRate()}" - } else { - "N/A" - } + "${it.getRecallRate()}" } ?: "0" } - - private fun isAllApplicable(vararg values: Long): Boolean = values.all { !CountWarnings.isNotApplicable(it.toInt()) } } /**