Skip to content

Commit

Permalink
Add review notes (#138)
Browse files Browse the repository at this point in the history
- revert throw declarations
- convert e messages to AbortExceptions
- enhance hint messages
- extend tests
  • Loading branch information
MarioFuchsTT committed Jun 7, 2024
1 parent 3058dad commit 46f4ca3
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,36 @@ class RunPackageStep extends RunTestStep {

@Override
protected TestResult run() throws Exception {
EnvVars envVars = context.get(EnvVars.class)
String expTestCasePath = envVars.expand(step.testCasePath)
TestConfig expTestConfig = step.testConfig.expand(envVars)
PackageConfig expPackageConfig = step.packageConfig.expand(envVars)
AnalysisConfig expAnalysisConfig = step.analysisConfig.expand(envVars)
try {
EnvVars envVars = context.get(EnvVars.class)
String expTestCasePath = envVars.expand(step.testCasePath)
TestConfig expTestConfig = step.testConfig.expand(envVars)
PackageConfig expPackageConfig = step.packageConfig.expand(envVars)
AnalysisConfig expAnalysisConfig = step.analysisConfig.expand(envVars)

checkPackagePath(expTestCasePath)

TestPackageBuilder testPackage = new TestPackageBuilder(expTestCasePath, expTestConfig,
step.executionConfig, context, expPackageConfig, expAnalysisConfig)
TestResult result = testPackage.runTest()
checkPackagePath(expTestCasePath)

addBuildAction(context.get(Run.class), expTestCasePath, expTestConfig, expPackageConfig, expAnalysisConfig,
result)
TestPackageBuilder testPackage = new TestPackageBuilder(expTestCasePath, expTestConfig,
step.executionConfig, context, expPackageConfig, expAnalysisConfig)
TestResult result = testPackage.runTest()

return result
addBuildAction(context.get(Run.class), expTestCasePath, expTestConfig, expPackageConfig, expAnalysisConfig,
result)

return result

} catch (Exception e) {
throw new AbortException(e.getMessage())
}
}

private void checkPackagePath(String packageFile) {
private void checkPackagePath(String packageFile)
throws IOException, InterruptedException, IllegalArgumentException {
if (IOUtils.isAbsolute(packageFile)) {
FilePath packagePath = new FilePath(context.get(Launcher.class).getChannel(), packageFile)
if (!packagePath.exists()) {
throw new AbortException("ecu.test package at ${packagePath.getRemote()} does not exist!" +
throw new AbortException("ecu.test package at ${packagePath.getRemote()} does not exist! " +
"Please ensure that the path is correctly set and it refers to the desired directory.")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,33 @@ class RunProjectStep extends RunTestStep {

@Override
protected TestResult run() throws Exception {
EnvVars envVars = context.get(EnvVars.class)
String expTestCasePath = envVars.expand(step.testCasePath)
TestConfig expTestConfig = step.testConfig.expand(envVars)
try {
EnvVars envVars = context.get(EnvVars.class)
String expTestCasePath = envVars.expand(step.testCasePath)
TestConfig expTestConfig = step.testConfig.expand(envVars)

checkProjectPath(expTestCasePath)
checkProjectPath(expTestCasePath)

TestProjectBuilder testProject = new TestProjectBuilder(expTestCasePath, expTestConfig,
step.getExecutionConfig(), context)
TestResult result = testProject.runTest()
TestProjectBuilder testProject = new TestProjectBuilder(expTestCasePath, expTestConfig,
step.getExecutionConfig(), context)
TestResult result = testProject.runTest()

addBuildAction(context.get(Run.class), expTestCasePath, expTestConfig, result)
addBuildAction(context.get(Run.class), expTestCasePath, expTestConfig, result)

return result
return result

} catch (Exception e) {
throw new AbortException(e.getMessage())

}
}

private void checkProjectPath(String projectFile) {
private void checkProjectPath(String projectFile)
throws IOException, InterruptedException, IllegalArgumentException {
if (IOUtils.isAbsolute(projectFile)) {
FilePath projectPath = new FilePath(context.get(Launcher.class).getChannel(), projectFile)
if (!projectPath.exists()) {
throw new AbortException("ecu.test project at ${projectPath.getRemote()} does not exist!" +
throw new AbortException("ecu.test project at ${projectPath.getRemote()} does not exist! " +
"Please ensure that the path is correctly set and it refers to the desired directory.")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,73 +130,75 @@ class RunTestFolderStep extends RunTestStep {

@Override
protected List<TestResult> run() throws Exception {
List<TestResult> testResultList = new ArrayList<>()
EnvVars envVars = context.get(EnvVars.class)
String expTestCasePath = envVars.expand(step.testCasePath)
ExecutionConfig expExecutionConfig = step.executionConfig
TestConfig expTestConfig = step.testConfig.expand(envVars)
PackageConfig expPackageConfig = step.packageConfig.expand(envVars)
AnalysisConfig expAnalysisConfig = step.analysisConfig.expand(envVars)

String testFolderPath = checkFolder(expTestCasePath)

final List<String> pkgFiles = scanPackages(testFolderPath, context, step.scanMode, step.recursiveScan)
final List<String> prjFiles = scanProjects(testFolderPath, context, step.scanMode, step.recursiveScan)


pkgFiles.each { pkgFile ->
TestPackageBuilder testPackage = new TestPackageBuilder(pkgFile, expTestConfig,
expExecutionConfig, context, expPackageConfig, expAnalysisConfig)
TestResult result = testPackage.runTest()
testResultList.add(result)
if (result.getTestResult() == 'FAILED' && isFailFast()) {
return testResultList
try {
List<TestResult> testResultList = new ArrayList<>()
EnvVars envVars = context.get(EnvVars.class)
String expTestCasePath = envVars.expand(step.testCasePath)
ExecutionConfig expExecutionConfig = step.executionConfig
TestConfig expTestConfig = step.testConfig.expand(envVars)
PackageConfig expPackageConfig = step.packageConfig.expand(envVars)
AnalysisConfig expAnalysisConfig = step.analysisConfig.expand(envVars)

String testFolderPath = checkFolder(expTestCasePath)

final List<String> pkgFiles = scanPackages(testFolderPath, context, step.scanMode, step.recursiveScan)
final List<String> prjFiles = scanProjects(testFolderPath, context, step.scanMode, step.recursiveScan)


pkgFiles.each { pkgFile ->
TestPackageBuilder testPackage = new TestPackageBuilder(pkgFile, expTestConfig,
expExecutionConfig, context, expPackageConfig, expAnalysisConfig)
TestResult result = testPackage.runTest()
testResultList.add(result)
if (result.getTestResult() == 'FAILED' && isFailFast()) {
return testResultList
}
}
}

prjFiles.each { prjFile ->
TestProjectBuilder testProject = new TestProjectBuilder(prjFile, expTestConfig,
expExecutionConfig, context)
TestResult result = testProject.runTest()
testResultList.add(result)
if (result.getTestResult() == 'FAILED' && isFailFast()) {
return testResultList
prjFiles.each { prjFile ->
TestProjectBuilder testProject = new TestProjectBuilder(prjFile, expTestConfig,
expExecutionConfig, context)
TestResult result = testProject.runTest()
testResultList.add(result)
if (result.getTestResult() == 'FAILED' && isFailFast()) {
return testResultList
}
}
}

return testResultList
return testResultList

} catch (Exception e) {
throw new AbortException(e.getMessage())
}
}

private String checkFolder(String folder) {
private String checkFolder(String folder)
throws IOException, InterruptedException, IllegalArgumentException {
if (IOUtils.isAbsolute(folder)) {
FilePath folderPath = new FilePath(context.get(Launcher.class).getChannel(), folder)
if (!folderPath.exists()) {
throw new AbortException("ecu.test folder at ${folderPath.getRemote()} does not extist!" +
throw new AbortException("ecu.test folder at ${folderPath.getRemote()} does not extist! " +
"Please ensure that the path is correctly set and it refers to the desired directory.")
}
return folderPath.getRemote()
} else {
throw new AbortException("Unsupported relative paths for ecu.test folder '${folder}'!" +
"Please ensure that the path is correctly set and it refers to the desired directory.")
throw new AbortException("Unsupported relative paths for ecu.test folder '${folder}'! " +
"Please ensure that the path is correctly set and it refers to the desired directory. " +
"Consider using an absolute path instead.")
}
}
}

private static List<String> scanPackages(final String testFolder, final StepContext context,
ScanMode scanMode, boolean isRecursive) {
ScanMode scanMode, boolean isRecursive)
throws IOException, InterruptedException {
List<String> pkgFiles = new ArrayList<>()
if (scanMode == ScanMode.PROJECTS_ONLY) {
return pkgFiles
}

try {
final TestPackageScanner scanner = new TestPackageScanner(testFolder, isRecursive, context)
pkgFiles = scanner.scanTestFiles()
} catch (IOException | InterruptedException e) {
throw new AbortException("Failed to scan packages in the folder: '${testFolder}'" +
"Please ensure that the path is correctly set and it refers to the desired directory.")
}

final TestPackageScanner scanner = new TestPackageScanner(testFolder, isRecursive, context)
pkgFiles = scanner.scanTestFiles()
if (pkgFiles.isEmpty()) {
context.get(TaskListener.class).logger.println('No packages found!')
} else {
Expand All @@ -207,20 +209,15 @@ class RunTestFolderStep extends RunTestStep {
}

private static List<String> scanProjects(final String testFolder, final StepContext context,
ScanMode scanMode, boolean isRecursive) {
ScanMode scanMode, boolean isRecursive)
throws IOException, InterruptedException {
List<String> prjFiles = new ArrayList<>()
if (scanMode == ScanMode.PACKAGES_ONLY) {
return prjFiles
}

try {
final TestProjectScanner scanner = new TestProjectScanner(testFolder, isRecursive, context)
prjFiles = scanner.scanTestFiles()
} catch (IOException | InterruptedException e) {
throw new AbortException("Failed to scan projects in the folder: '${testFolder}'" +
"Please ensure that the path is correctly set and it refers to the desired directory.")
}

final TestProjectScanner scanner = new TestProjectScanner(testFolder, isRecursive, context)
prjFiles = scanner.scanTestFiles()
if (prjFiles.isEmpty()) {
context.get(TaskListener.class).logger.println('No projects found!')
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,17 @@ class StartToolStep extends Step {
step.stopUndefinedTools, envVars, context.get(TaskListener.class)))
} catch (Exception e) {
context.get(Run.class).setResult(Result.FAILURE)
throw(e) // there is no friendly option to stop the step execution without an exception
// there is no friendly option to stop the step execution without an exception
throw new AbortException(e.getMessage())
}
}

private void checkWorkspace(String workspaceDir, String settingsDir) {
private void checkWorkspace(String workspaceDir, String settingsDir)
throws IOException, InterruptedException, IllegalArgumentException {
FilePath workspacePath = new FilePath(context.get(Launcher.class).getChannel(), workspaceDir)
if (!workspacePath.exists()) {
throw new AbortException(
"ecu.test workspace directory at ${workspacePath.getRemote()} does not exist!" +
"ecu.test workspace directory at ${workspacePath.getRemote()} does not exist! " +
"Please ensure that the path is correctly set and it refers to the desired directory.")
}

Expand Down Expand Up @@ -196,29 +198,34 @@ class StartToolStep extends Step {
}

@Override
Void call() {
String toolName = installation.getName()
if (keepInstance) {
listener.logger.println("Re-using running instance ${toolName}...")
connectTool(toolName)
} else {
if (stopUndefinedTools) {
listener.logger.println("Stop tracetronic tool instances.")
if (ProcessUtil.killTTProcesses(timeout)) {
listener.logger.println("Stopped tracetronic tools successfully.")
} else {
throw new AbortException(
"Timeout of ${this.timeout} seconds exceeded for stopping tracetronic tools!" +
"Please ensure that tracetronic tools are not already stopped.")
Void call() throws TimeoutException {
try {
String toolName = installation.getName()
if (keepInstance) {
listener.logger.println("Re-using running instance ${toolName}...")
connectTool(toolName)
} else {
if (stopUndefinedTools) {
listener.logger.println("Stop tracetronic tool instances.")
if (ProcessUtil.killTTProcesses(timeout)) {
listener.logger.println("Stopped tracetronic tools successfully.")
} else {
throw new AbortException(
"Timeout of ${this.timeout} seconds exceeded for stopping tracetronic tools! " +
"Please ensure that tracetronic tools are not already stopped or " +
"blocked by another process.")
}
}
listener.logger.println("Starting ${toolName}...")
checkLicense(toolName)
startTool(toolName)
connectTool(toolName)
listener.logger.println("${toolName} started successfully.")
}
listener.logger.println("Starting ${toolName}...")
checkLicense(toolName)
startTool(toolName)
connectTool(toolName)
listener.logger.println("${toolName} started successfully.")
return null
} catch (Exception e) {
throw new AbortException(e.getMessage())
}
return null
}

/**
Expand Down Expand Up @@ -251,22 +258,23 @@ class StartToolStep extends Step {
exitCode = future.get(timeout, TimeUnit.SECONDS)
}
if (exitCode != 0) {
throw new AbortException("No valid license found for ${toolName}!" +
throw new AbortException("No valid license found for ${toolName}! " +
"Please ensure the license is not expired or corrupted.")
}
} catch (TimeoutException ignored) {
process.destroy()
throw new AbortException(
"Timeout of ${this.timeout} seconds exceeded for checking license of ${toolName}!" +
"Timeout of ${this.timeout} seconds exceeded for checking license of ${toolName}! " +
"Please ensure the license server is active and responsive.")
}
}

/**
* Starts the tool (ecu.test or trace.check) with CLI parameters.
* @param toolName the name of the tool, as defined in the Jenkins tool installation settings.
* @throws IllegalStateException
*/
private void startTool(String toolName) {
private void startTool(String toolName) throws IllegalStateException {
ArgumentListBuilder args = new ArgumentListBuilder()
args.add(installation.exeFileOnNode.absolutePath)
args.add('--workspaceDir', workspaceDir)
Expand All @@ -288,7 +296,7 @@ class StartToolStep extends Step {

if (!isStarted) {
throw new AbortException(
"Timeout of ${this.timeout} seconds exceeded for starting ${toolName}!" +
"Timeout of ${this.timeout} seconds exceeded for starting ${toolName}! " +
"Please ensure that the tool is correctly configured and accessible.")
}
}
Expand All @@ -302,8 +310,8 @@ class StartToolStep extends Step {
RestApiClientFactory.getRestApiClient(envVars.get('ET_API_HOSTNAME'), envVars.get('ET_API_PORT'), timeout)
} catch (ApiException e) {
throw new AbortException(
"Timeout of ${this.timeout} seconds exceeded for connecting to ${toolName}!" +
"Please ensure the tool is running and its API endpoint is accessible.")
"Timeout of ${this.timeout} seconds exceeded for connecting to ${toolName}! " +
"Please ensure the tool is correctly started and consider restarting it.")
}
}
}
Expand Down
Loading

0 comments on commit 46f4ca3

Please sign in to comment.