From 0ee6258d743d867f6048b15db5ac06546137151d Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 27 Nov 2024 17:27:13 +0300 Subject: [PATCH] add coverage cleanup in bdd, smoke --- .../pulsar/jenkins/library/steps/Bdd.groovy | 44 +++++++++++++------ .../library/steps/CoverageCleanup.groovy | 5 +-- .../jenkins/library/steps/SmokeTest.groovy | 18 ++++++++ .../jenkins/library/steps/Yaxunit.groovy | 2 +- vars/pipeline1C.groovy | 10 +++++ 5 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/ru/pulsar/jenkins/library/steps/Bdd.groovy b/src/ru/pulsar/jenkins/library/steps/Bdd.groovy index c365a75d..e19cc4dd 100644 --- a/src/ru/pulsar/jenkins/library/steps/Bdd.groovy +++ b/src/ru/pulsar/jenkins/library/steps/Bdd.groovy @@ -3,6 +3,7 @@ package ru.pulsar.jenkins.library.steps import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.utils.CoverageUtils import ru.pulsar.jenkins.library.utils.FileUtils import ru.pulsar.jenkins.library.utils.Logger import org.apache.commons.lang.RandomStringUtils @@ -15,6 +16,7 @@ class Bdd implements Serializable { public static final String ALLURE_STASH = 'bdd-allure' public static final String COVERAGE_STASH_NAME = 'bdd-coverage' public static final String COVERAGE_STASH_PATH = 'build/out/bdd-coverage.xml' + public static final String COVERAGE_PIDS_PATH = 'build/bdd-pids' Bdd(JobConfiguration config) { this.config = config @@ -43,6 +45,8 @@ class Bdd implements Serializable { def coverageOpts = config.coverageOptions def port = options.dbgsPort + def currentDbgsPids = CoverageUtils.getPIDs("dbgs") + def currentCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") def lockableResource = RandomStringUtils.random(9, true, false) if (options.coverage) { @@ -54,22 +58,36 @@ class Bdd implements Serializable { steps.start("${coverageOpts.dbgsPath} --addr=127.0.0.1 --port=$port") steps.start("${coverageOpts.coverage41CPath} start -i DefAlias -u http://127.0.0.1:$port -P $workspaceDir -s $srcDir -o $COVERAGE_STASH_PATH") steps.cmd("${coverageOpts.coverage41CPath} check -i DefAlias -u http://127.0.0.1:$port") + + def newDbgsPids = CoverageUtils.getPIDs("dbgs") + def newCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") + + newDbgsPids.removeAll(currentDbgsPids) + newCoverage41CPids.removeAll(currentCoverage41CPids) + + newDbgsPids.addAll(newCoverage41CPids) + def pids = newDbgsPids.join(" ") + + steps.writeFile(COVERAGE_PIDS_PATH, pids, 'UTF-8') + + Logger.println("Coverage PIDs for cleanup: $pids") + } - config.bddOptions.vrunnerSteps.each { - Logger.println("Шаг запуска сценариев командой ${it}") - String vrunnerPath = VRunner.getVRunnerPath() - Integer bddReturnStatus = VRunner.exec("$vrunnerPath ${it} --ibconnection \"/F./build/ib\"", true) - returnStatuses.add(bddReturnStatus) - } + config.bddOptions.vrunnerSteps.each { + Logger.println("Шаг запуска сценариев командой ${it}") + String vrunnerPath = VRunner.getVRunnerPath() + Integer bddReturnStatus = VRunner.exec("$vrunnerPath ${it} --ibconnection \"/F./build/ib\"", true) + returnStatuses.add(bddReturnStatus) + } - if (Collections.max(returnStatuses) > 2) { - steps.error("Получен неожиданный/неверный результат работы. Возможно, работа 1С:Предприятие завершилась некорректно, или возникла ошибка при запуске") - } else if (returnStatuses.contains(1)) { - steps.unstable("Тестирование сценариев завершилось, но часть фич/сценариев упала") - } else { - Logger.println("Тестирование сценариев завершилось успешно") - } + if (Collections.max(returnStatuses) > 2) { + steps.error("Получен неожиданный/неверный результат работы. Возможно, работа 1С:Предприятие завершилась некорректно, или возникла ошибка при запуске") + } else if (returnStatuses.contains(1)) { + steps.unstable("Тестирование сценариев завершилось, но часть фич/сценариев упала") + } else { + Logger.println("Тестирование сценариев завершилось успешно") + } if (options.coverage) { steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port") diff --git a/src/ru/pulsar/jenkins/library/steps/CoverageCleanup.groovy b/src/ru/pulsar/jenkins/library/steps/CoverageCleanup.groovy index 4a66f576..ff73203a 100644 --- a/src/ru/pulsar/jenkins/library/steps/CoverageCleanup.groovy +++ b/src/ru/pulsar/jenkins/library/steps/CoverageCleanup.groovy @@ -22,10 +22,7 @@ class CoverageCleanup implements Serializable { Logger.printLocation() - String pidsFilePath = "" - if (stageName == 'yaxunit') { - pidsFilePath = Yaxunit.COVERAGE_PIDS_PATH - } + String pidsFilePath = "build/$stageName-pids" def pids = "" if (steps.fileExists(pidsFilePath)) { diff --git a/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy b/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy index 24571f2a..55ac5e5a 100644 --- a/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy +++ b/src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy @@ -5,6 +5,7 @@ import org.apache.commons.lang.RandomStringUtils import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.utils.CoverageUtils import ru.pulsar.jenkins.library.utils.FileUtils import ru.pulsar.jenkins.library.utils.Logger import ru.pulsar.jenkins.library.utils.StringJoiner @@ -15,6 +16,7 @@ class SmokeTest implements Serializable { public static final String ALLURE_STASH = 'smoke-allure' public static final String COVERAGE_STASH_NAME = 'smoke-coverage' public static final String COVERAGE_STASH_PATH = 'build/out/smoke-coverage.xml' + public static final String COVERAGE_PIDS_PATH = 'build/smoke-pids' private final JobConfiguration config @@ -108,6 +110,8 @@ class SmokeTest implements Serializable { def coverageOpts = config.coverageOptions def port = options.dbgsPort + def currentDbgsPids = CoverageUtils.getPIDs("dbgs") + def currentCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") def lockableResource = RandomStringUtils.random(9, true, false) if (options.coverage) { lockableResource = "${env.NODE_NAME}_$port" @@ -118,6 +122,20 @@ class SmokeTest implements Serializable { steps.start("${coverageOpts.dbgsPath} --addr=127.0.0.1 --port=$port") steps.start("${coverageOpts.coverage41CPath} start -i DefAlias -u http://127.0.0.1:$port -P $workspaceDir -s $srcDir -o $COVERAGE_STASH_PATH") steps.cmd("${coverageOpts.coverage41CPath} check -i DefAlias -u http://127.0.0.1:$port") + + def newDbgsPids = CoverageUtils.getPIDs("dbgs") + def newCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") + + newDbgsPids.removeAll(currentDbgsPids) + newCoverage41CPids.removeAll(currentCoverage41CPids) + + newDbgsPids.addAll(newCoverage41CPids) + def pids = newDbgsPids.join(" ") + + steps.writeFile(COVERAGE_PIDS_PATH, pids, 'UTF-8') + + Logger.println("Coverage PIDs for cleanup: $pids") + } steps.withEnv(logosConfig) { diff --git a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy index 70f2477f..ffffe60c 100644 --- a/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy +++ b/src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy @@ -73,9 +73,9 @@ class Yaxunit implements Serializable { def coverageOpts = config.coverageOptions def port = options.dbgsPort - def lockableResource = RandomStringUtils.random(9, true, false) def currentDbgsPids = CoverageUtils.getPIDs("dbgs") def currentCoverage41CPids = CoverageUtils.getPIDs("Coverage41C") + def lockableResource = RandomStringUtils.random(9, true, false) if (options.coverage) { lockableResource = "${env.NODE_NAME}_$port" } diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index 627bedf2..fd2e5e21 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -236,6 +236,11 @@ void call() { bdd config } } + post { + cleanup { + coverageCleanup config, 'bdd' + } + } } } } @@ -288,6 +293,11 @@ void call() { smoke config } } + post { + cleanup { + coverageCleanup config, 'smoke' + } + } } } }