Skip to content

Commit

Permalink
add coverage for yaxunit, fix smoke dbgs port
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Nov 17, 2024
1 parent 611dbc8 commit 4f40096
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
19 changes: 18 additions & 1 deletion resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,24 @@
},
"xddConfigPath" : {
"type" : "string",
"description" : "Путь к конфигурационному файлу для xddTestRunner.\n По умолчанию содержит значение \"./tools/xUnitParams.json\".\n "
"description" : "Путь к конфигурационному файлу YAXUnit.\n По умолчанию содержит значение \"./tools/yaxunit.json\".\n "
},
"publishToAllureReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет Allure.\n По умолчанию выключено.\n "
},
"publishToJUnitReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n "
},
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия"
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия"
}
}
},
"description" : "Настройки дымового тестирования"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SmokeTestOptions implements Serializable {
Boolean coverage = false

@JsonPropertyDescription("Порт, на котором будет запущен сервер отладки для замера покрытия")
int dbgsPort = 1650
int dbgsPort = 1550

@Override
@NonCPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class YaxunitOptions implements Serializable {
""")
boolean publishToJUnitReport

@JsonPropertyDescription("Выполнять замер покрытия")
Boolean coverage = false

@JsonPropertyDescription("Порт, на котором будет запущен сервер отладки для замера покрытия")
int dbgsPort = 1550

@Override
@NonCPS
String toString() {
Expand All @@ -35,6 +41,8 @@ class YaxunitOptions implements Serializable {
", configPath='" + configPath +
", publishToAllureReport='" + publishToAllureReport +
", publishToJUnitReport='" + publishToJUnitReport +
", coverage='" + coverage +
", dbgsPort='" + dbgsPort +
'}'
}
}
16 changes: 12 additions & 4 deletions src/ru/pulsar/jenkins/library/steps/SonarScanner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,29 @@ class SonarScanner implements Serializable {
}
}

if (config.stageFlags.bdd && config.bddOptions.coverage
|| config.stageFlags.smoke && config.smokeTestOptions.coverage) {
def stageFlags = config.stageFlags

if (stageFlags.bdd && config.bddOptions.coverage
|| stageFlags.smoke && config.smokeTestOptions.coverage
|| stageFlags.yaxunit && config.yaxunitOptions.coverage) {

StringJoiner coveragePathsConstructor = new StringJoiner(",")

if (config.stageFlags.bdd && config.bddOptions.coverage) {
if (stageFlags.bdd && config.bddOptions.coverage) {
steps.unstash(Bdd.COVERAGE_STASH_NAME)
coveragePathsConstructor.add(Bdd.COVERAGE_STASH_PATH)
}

if (config.stageFlags.smoke && config.smokeTestOptions.coverage) {
if (stageFlags.smoke && config.smokeTestOptions.coverage) {
steps.unstash(SmokeTest.COVERAGE_STASH_NAME)
coveragePathsConstructor.add(SmokeTest.COVERAGE_STASH_PATH)
}

if (stageFlags.yaxunit && config.yaxunitOptions.coverage) {
steps.unstash(Yaxunit.COVERAGE_STASH_NAME)
coveragePathsConstructor.add(Yaxunit.COVERAGE_STASH_PATH)
}

String coveragePaths = coveragePathsConstructor.toString()

sonarCommand += " -Dsonar.coverageReportPaths=${coveragePaths}"
Expand Down
32 changes: 29 additions & 3 deletions src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.pulsar.jenkins.library.steps

import hudson.FilePath
import org.apache.commons.lang.RandomStringUtils
import ru.pulsar.jenkins.library.IStepExecutor

import ru.pulsar.jenkins.library.configuration.JobConfiguration
Expand All @@ -16,6 +17,8 @@ class Yaxunit implements Serializable {
private final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json'

public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure'
public static final String COVERAGE_STASH_NAME = 'yaxunit-coverage'
public static final String COVERAGE_STASH_PATH = 'build/out/yaxunit-coverage.xml'

Yaxunit(JobConfiguration config) {
this.config = config
Expand Down Expand Up @@ -62,9 +65,28 @@ class Yaxunit implements Serializable {

}

// Выполяем команды
steps.withEnv(logosConfig) {
VRunner.exec(runTestsCommand, true)
def coverageOpts = config.coverageOptions
def port = options.dbgsPort
def lockableResource = RandomStringUtils.random(9, true, false)
if (options.coverage) {
lockableResource = "${env.NODE_NAME}_$port"
}

steps.lock(null, 1, lockableResource) {
if (options.coverage) {
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")
}

// Выполняем команды
steps.withEnv(logosConfig) {
VRunner.exec(runTestsCommand, true)
}

if (options.coverage) {
steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port")
}
}

// Сохраняем результаты
Expand All @@ -86,5 +108,9 @@ class Yaxunit implements Serializable {

steps.stash(YAXUNIT_ALLURE_STASH, "$allureReportDir/**", true)
}

if (options.coverage) {
steps.stash(COVERAGE_STASH_NAME, COVERAGE_STASH_PATH, true)
}
}
}

0 comments on commit 4f40096

Please sign in to comment.