Skip to content

Commit

Permalink
add coverage cleanup in bdd, smoke
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Nov 27, 2024
1 parent d38b72f commit 0ee6258
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 18 deletions.
44 changes: 31 additions & 13 deletions src/ru/pulsar/jenkins/library/steps/Bdd.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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")
Expand Down
5 changes: 1 addition & 4 deletions src/ru/pulsar/jenkins/library/steps/CoverageCleanup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
18 changes: 18 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
10 changes: 10 additions & 0 deletions vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ void call() {
bdd config
}
}
post {
cleanup {
coverageCleanup config, 'bdd'
}
}
}
}
}
Expand Down Expand Up @@ -288,6 +293,11 @@ void call() {
smoke config
}
}
post {
cleanup {
coverageCleanup config, 'smoke'
}
}
}
}
}
Expand Down

0 comments on commit 0ee6258

Please sign in to comment.