From a0414e8dab7b715a3803d2a55101476c7bcba3e1 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 15:53:17 +0300 Subject: [PATCH 1/7] Don't recalculate counters in Execution if value is `NOT_APPLICABLE` --- .../backend/service/TestExecutionService.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 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..6a18bd7905 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 @@ -13,10 +14,7 @@ import com.saveourtool.save.entities.Test import com.saveourtool.save.entities.TestExecution import com.saveourtool.save.execution.TestExecutionFilters 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 @@ -170,7 +168,7 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep ) @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 +210,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 += unmatchedChecks.increaseIfApplicable(testExecDto.unmatched) + matchedChecks += matchedChecks.increaseIfApplicable(testExecDto.matched) + expectedChecks += expectedChecks.increaseIfApplicable(testExecDto.expected) + unexpectedChecks += unexpectedChecks.increaseIfApplicable(testExecDto.unexpected) + } testExecutionRepository.save(it) }, @@ -229,9 +229,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 @@ -241,8 +242,6 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep matchedChecks += counters.matchedChecks expectedChecks += counters.expectedChecks unexpectedChecks += counters.unexpectedChecks - - score = toDto().calculateScore(scoreType = ScoreType.F_MEASURE) } executionRepository.save(execution) } @@ -352,6 +351,10 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep } } + private fun Long.increaseIfApplicable(delta: Long?) = takeUnless { CountWarnings.isNotApplicable(it.toInt()) } + ?.plus(delta ?: 0L) + ?: 0L + @Suppress( "KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_ON_FUNCTION", From 27c23253464b7d0d1f6196377cee4cb38aa044be Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 15:56:37 +0300 Subject: [PATCH 2/7] Update TestExecutionService.kt --- .../saveourtool/save/backend/service/TestExecutionService.kt | 4 ++++ 1 file changed, 4 insertions(+) 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 6a18bd7905..9180fc59f4 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 @@ -14,6 +14,8 @@ import com.saveourtool.save.entities.Test import com.saveourtool.save.entities.TestExecution import com.saveourtool.save.execution.TestExecutionFilters 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.getLogger @@ -242,6 +244,8 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep matchedChecks += counters.matchedChecks expectedChecks += counters.expectedChecks unexpectedChecks += counters.unexpectedChecks + + score = toDto().calculateScore(scoreType = ScoreType.F_MEASURE) } executionRepository.save(execution) } From 51316743ff4bde92f01cb183d57255cafd2f178d Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 15:57:07 +0300 Subject: [PATCH 3/7] Update TestExecutionService.kt --- .../saveourtool/save/backend/service/TestExecutionService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9180fc59f4..850344b9f7 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 @@ -212,7 +212,7 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep it.expected = testExecDto.expected it.unexpected = testExecDto.unexpected - with (counters) { + with(counters) { unmatchedChecks += unmatchedChecks.increaseIfApplicable(testExecDto.unmatched) matchedChecks += matchedChecks.increaseIfApplicable(testExecDto.matched) expectedChecks += expectedChecks.increaseIfApplicable(testExecDto.expected) From 7eb401eb13f9a677f1f7b91992efc8e27054feb6 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 16:31:46 +0300 Subject: [PATCH 4/7] Don't display metrics only if all test execution are `NOT_APPLICABLE` --- .../frontend/components/basic/ExecutionLabels.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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..a3a9cdcfbe 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 @@ -101,25 +101,25 @@ internal class ExecutionStatisticsValues(executionDto: ExecutionDto?) { ?: "0" this.precisionRate = executionDto ?.let { - if (isAllApplicable(it.matchedChecks, it.unexpectedChecks)) { - "${it.getPrecisionRate()}" - } else { + if (isNoneApplicable(it.matchedChecks, it.unexpectedChecks)) { "N/A" + } else { + "${it.getPrecisionRate()}" } } ?: "0" this.recallRate = executionDto ?.let { - if (isAllApplicable(it.matchedChecks, it.unmatchedChecks)) { - "${it.getRecallRate()}" - } else { + if (isNoneApplicable(it.matchedChecks, it.unmatchedChecks)) { "N/A" + } else { + "${it.getRecallRate()}" } } ?: "0" } - private fun isAllApplicable(vararg values: Long): Boolean = values.all { !CountWarnings.isNotApplicable(it.toInt()) } + private fun isNoneApplicable(vararg values: Long): Boolean = values.all { CountWarnings.isNotApplicable(it.toInt()) } } /** From 1d287cb1ee6c1e6c5f65d820bf4c28e00197fab3 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 16:33:17 +0300 Subject: [PATCH 5/7] Code style --- .../com/saveourtool/save/backend/service/TestExecutionService.kt | 1 + 1 file changed, 1 insertion(+) 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 850344b9f7..ac8fbf6f6e 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 @@ -167,6 +167,7 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep "LongMethod", "MAGIC_NUMBER", "MagicNumber", + "PARAMETER_NAME_IN_OUTER_LAMBDA", ) @Transactional fun saveTestResult(testExecutionsDtos: List): List { From 710f960fb30d22321c75d7942c8e8f6bb0372690 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 16:53:59 +0300 Subject: [PATCH 6/7] Fixes --- .../save/backend/service/TestExecutionService.kt | 12 +++++------- .../frontend/components/basic/ExecutionLabels.kt | 14 ++------------ 2 files changed, 7 insertions(+), 19 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 ac8fbf6f6e..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 @@ -214,10 +214,10 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep it.unexpected = testExecDto.unexpected with(counters) { - unmatchedChecks += unmatchedChecks.increaseIfApplicable(testExecDto.unmatched) - matchedChecks += matchedChecks.increaseIfApplicable(testExecDto.matched) - expectedChecks += expectedChecks.increaseIfApplicable(testExecDto.expected) - unexpectedChecks += unexpectedChecks.increaseIfApplicable(testExecDto.unexpected) + unmatchedChecks += testExecDto.unmatched.orZeroIfNotApplicable() + matchedChecks += testExecDto.matched.orZeroIfNotApplicable() + expectedChecks += testExecDto.expected.orZeroIfNotApplicable() + unexpectedChecks += testExecDto.unexpected.orZeroIfNotApplicable() } testExecutionRepository.save(it) @@ -356,9 +356,7 @@ class TestExecutionService(private val testExecutionRepository: TestExecutionRep } } - private fun Long.increaseIfApplicable(delta: Long?) = takeUnless { CountWarnings.isNotApplicable(it.toInt()) } - ?.plus(delta ?: 0L) - ?: 0L + private fun Long?.orZeroIfNotApplicable() = this?.takeUnless { CountWarnings.isNotApplicable(it.toInt()) } ?: 0 @Suppress( "KDOC_NO_CONSTRUCTOR_PROPERTY", 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 a3a9cdcfbe..4994fa3471 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 @@ -101,25 +101,15 @@ internal class ExecutionStatisticsValues(executionDto: ExecutionDto?) { ?: "0" this.precisionRate = executionDto ?.let { - if (isNoneApplicable(it.matchedChecks, it.unexpectedChecks)) { - "N/A" - } else { - "${it.getPrecisionRate()}" - } + "${it.getPrecisionRate()}" } ?: "0" this.recallRate = executionDto ?.let { - if (isNoneApplicable(it.matchedChecks, it.unmatchedChecks)) { - "N/A" - } else { - "${it.getRecallRate()}" - } + "${it.getRecallRate()}" } ?: "0" } - - private fun isNoneApplicable(vararg values: Long): Boolean = values.all { CountWarnings.isNotApplicable(it.toInt()) } } /** From 2fa013fe8b7f5ae31ffb0c4ad34b1c1a8ece181d Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 6 Sep 2022 16:59:29 +0300 Subject: [PATCH 7/7] Update ExecutionLabels.kt --- .../save/frontend/components/basic/ExecutionLabels.kt | 1 - 1 file changed, 1 deletion(-) 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 4994fa3471..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