Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Nov 29, 2024
1 parent a7b557e commit e8e3db5
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 101 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
1. Для запуска шагов, работающих с 1С (подготовка, синтаксический контроль и т.д.) требуется агент с меткой, совпадающей со значением в поле `v8version` файла конфигурации.
1. В качестве ИБ используется файловая база, создаваемая в каталоге `./build/ib`. При необходимости вы можете создать пользователей на фазе инициализации ИБ.
1. Для замеров покрытия на агентах должны быть установлены [Coverage41C](https://github.com/1c-syntax/Coverage41C), EDT и сервер отладки dbgs. Вместо установки EDT целиком можно использовать только отдельные ее компоненты, см. [Coverage41C/README.md](https://github.com/1c-syntax/Coverage41C).
1. На данный момент ошибка в [vanessa-add](https://github.com/vanessa-opensource/add/issues/1152) не позволяет собирать замеры производительности в дымовых тестах по открытию всех форм на клиенте тестирования.
1. Для параллельного выполнения шагов `bdd` и `smoke` с включенными замерами покрытия на одной ноде необходимо, чтобы в `jobConfiguration.json` были указаны **разные** порты сервера отладки для каждого шага. Параллельные билды с замерами покрытия на одной ноде не поддерживаются.

## Возможности
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonPropertyDescription

@JsonIgnoreProperties(ignoreUnknown = true)
class BddOptions implements Serializable {
class BddOptions extends StepCoverageOptions implements Serializable {

@JsonPropertyDescription("""Шаги, запускаемые через vrunner.
В каждой строке передается отдельная команда
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonPropertyDescription

@JsonIgnoreProperties(ignoreUnknown = true)
class CoverageOptions implements Serializable {
class GlobalCoverageOptions implements Serializable {

@JsonPropertyDescription('''Путь к исполняемому файлу dbgs.
По умолчанию равен /opt/1cv8/current/dbgs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class JobConfiguration implements Serializable {

@JsonProperty("coverage")
@JsonPropertyDescription("Настройки замеров покрытия")
CoverageOptions coverageOptions;
GlobalCoverageOptions coverageOptions

@JsonProperty("yaxunit")
@JsonPropertyDescription("Настройки YAXUnit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonPropertyDescription

@JsonIgnoreProperties(ignoreUnknown = true)
class SmokeTestOptions implements Serializable {
class SmokeTestOptions extends StepCoverageOptions implements Serializable {

@JsonPropertyDescription("""Путь к конфигурационному файлу vanessa-runner.
По умолчанию содержит значение "./tools/vrunner.json".
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.pulsar.jenkins.library.configuration

import com.fasterxml.jackson.annotation.JsonPropertyDescription

class StepCoverageOptions {

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonPropertyDescription

@JsonIgnoreProperties(ignoreUnknown = true)
class YaxunitOptions implements Serializable {
class YaxunitOptions extends StepCoverageOptions implements Serializable {

@JsonPropertyDescription("""Путь к конфигурационному файлу vanessa-runner.
По умолчанию содержит значение "./tools/vrunner.json".
Expand Down
46 changes: 15 additions & 31 deletions src/ru/pulsar/jenkins/library/steps/Bdd.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ 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.lang3.RandomStringUtils
import ru.pulsar.jenkins.library.utils.VRunner

class Bdd implements Serializable {
class Bdd implements Serializable, Coverable {

private final JobConfiguration config

Expand Down Expand Up @@ -44,34 +43,11 @@ class Bdd implements Serializable {
List<Integer> returnStatuses = []

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"
}

steps.lock(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")

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")
def coverageContext = CoverageUtils.prepareContext(config, options)

steps.lock(coverageContext.lockableResource) {
if (coverageContext != null) {
CoverageUtils.startCoverage(steps, coverageOpts, coverageContext, workspaceDir, srcDir, this)
}

config.bddOptions.vrunnerSteps.each {
Expand All @@ -89,8 +65,8 @@ class Bdd implements Serializable {
Logger.println("Тестирование сценариев завершилось успешно")
}

if (options.coverage) {
steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port")
if (coverageContext != null) {
CoverageUtils.stopCoverage(steps, coverageOpts, coverageContext)
}
}
}
Expand All @@ -102,4 +78,12 @@ class Bdd implements Serializable {
}

}

String getCoverageStashPath() {
return COVERAGE_STASH_PATH
}

String getCoveragePidsPath() {
return COVERAGE_PIDS_PATH
}
}
8 changes: 8 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/Coverable.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.pulsar.jenkins.library.steps

interface Coverable {

String getCoverageStashPath();
String getCoveragePidsPath();

}
23 changes: 23 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/CoverageContext.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.pulsar.jenkins.library.steps

import ru.pulsar.jenkins.library.configuration.GlobalCoverageOptions

class CoverageContext {

String lockableResource
GlobalCoverageOptions coverageOptions
int port
ArrayList<String> pids
ArrayList<String> dbgsPids
ArrayList<String> coverage41CPids

CoverageContext(String lockableResource, GlobalCoverageOptions coverageOptions, int port, ArrayList<String> dbgsPids, ArrayList<String> coverage41CPids) {
this.lockableResource = lockableResource
this.coverageOptions = coverageOptions
this.port = port
this.pids = dbgsPids + coverage41CPids
this.dbgsPids = dbgsPids
this.coverage41CPids = coverage41CPids
}

}
8 changes: 4 additions & 4 deletions src/ru/pulsar/jenkins/library/steps/GetExtensions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetExtensions implements Serializable {
public static final String EXTENSIONS_STASH = 'extensions'
public static final String EXTENSIONS_OUT_DIR = 'build/out/cfe'

private final JobConfiguration config;
private final JobConfiguration config

GetExtensions(JobConfiguration config) {
this.config = config
Expand All @@ -29,9 +29,9 @@ class GetExtensions implements Serializable {

def env = steps.env()

steps.installLocalDependencies();
steps.installLocalDependencies()

String vrunnerPath = initVRunnerPath();
String vrunnerPath = initVRunnerPath()

Logger.println("Сборка расширений")

Expand Down Expand Up @@ -88,7 +88,7 @@ class GetExtensions implements Serializable {

private void extractConvertedExtensions(String sourceDirName, IStepExecutor steps) {
if (config.sourceFormat == SourceFormat.EDT) {
// usntash and unzip the edt to designer format transformation
// unstash and unzip the edt to designer format transformation
steps.unstash(EdtToDesignerFormatTransformation.EXTENSION_ZIP_STASH)
steps.unzip(sourceDirName, EdtToDesignerFormatTransformation.EXTENSION_ZIP)
}
Expand Down
45 changes: 15 additions & 30 deletions src/ru/pulsar/jenkins/library/steps/SmokeTest.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.pulsar.jenkins.library.steps

import hudson.FilePath
import org.apache.commons.lang3.RandomStringUtils
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.ioc.ContextRegistry
Expand All @@ -11,7 +10,7 @@ import ru.pulsar.jenkins.library.utils.Logger
import ru.pulsar.jenkins.library.utils.StringJoiner
import ru.pulsar.jenkins.library.utils.VRunner

class SmokeTest implements Serializable {
class SmokeTest implements Serializable, Coverable {

public static final String ALLURE_STASH = 'smoke-allure'
public static final String COVERAGE_STASH_NAME = 'smoke-coverage'
Expand Down Expand Up @@ -109,41 +108,19 @@ 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"
}

steps.lock(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")

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")
def coverageContext = CoverageUtils.prepareContext(config, options)

steps.lock(coverageContext.lockableResource) {
if (coverageContext != null) {
CoverageUtils.startCoverage(steps, coverageOpts, coverageContext, workspaceDir, srcDir, this)
}

steps.withEnv(logosConfig) {
VRunner.exec(command, true)
}

if (options.coverage) {
steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port")
if (coverageContext != null) {
CoverageUtils.stopCoverage(steps, coverageOpts, coverageContext)
}
}

Expand All @@ -162,4 +139,12 @@ class SmokeTest implements Serializable {
}

}

String getCoverageStashPath() {
return COVERAGE_STASH_PATH
}

String getCoveragePidsPath() {
return COVERAGE_PIDS_PATH
}
}
48 changes: 17 additions & 31 deletions src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package ru.pulsar.jenkins.library.steps

import hudson.FilePath
import org.apache.commons.lang3.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.VRunner

class Yaxunit implements Serializable {
class Yaxunit implements Serializable, Coverable {

private final JobConfiguration config

Expand Down Expand Up @@ -72,42 +70,20 @@ class Yaxunit 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"
}

steps.lock(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")

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")
def coverageContext = CoverageUtils.prepareContext(config, options)

steps.lock(coverageContext.lockableResource) {
if (coverageContext != null) {
CoverageUtils.startCoverage(steps, coverageOpts, coverageContext, workspaceDir, srcDir, this)
}

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

if (options.coverage) {
steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port")
if (coverageContext != null) {
CoverageUtils.stopCoverage(steps, coverageOpts, coverageContext)
}
}

Expand Down Expand Up @@ -137,4 +113,14 @@ class Yaxunit implements Serializable {
steps.stash(COVERAGE_STASH_NAME, COVERAGE_STASH_PATH, true)
}
}

String getCoverageStashPath() {
return COVERAGE_STASH_PATH
}

String getCoveragePidsPath() {
return COVERAGE_PIDS_PATH
}


}
Loading

0 comments on commit e8e3db5

Please sign in to comment.