From 46f4ca3d93f5b9fc6fca055e455d00a9d2545b64 Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Fri, 7 Jun 2024 12:49:40 +0200 Subject: [PATCH] Add review notes (#138) - revert throw declarations - convert e messages to AbortExceptions - enhance hint messages - extend tests --- .../steps/RunPackageStep.groovy | 35 +++--- .../steps/RunProjectStep.groovy | 29 +++-- .../steps/RunTestFolderStep.groovy | 103 +++++++++--------- .../steps/StartToolStep.groovy | 66 ++++++----- .../steps/StopToolStep.groovy | 12 +- .../steps/RunPackageStepIT.groovy | 13 +++ .../steps/RunProjectStepIT.groovy | 13 +++ .../steps/RunTestFolderStepIT.groovy | 24 ++++ .../steps/StartToolStepIT.groovy | 33 ++++++ .../steps/StopToolStepIT.groovy | 8 +- 10 files changed, 222 insertions(+), 114 deletions(-) diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStep.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStep.groovy index c9b6c50d..20812fba 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStep.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStep.groovy @@ -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.") } } diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStep.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStep.groovy index e0246946..506947c5 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStep.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStep.groovy @@ -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.") } } diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStep.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStep.groovy index 07623b28..ea9dc277 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStep.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStep.groovy @@ -130,73 +130,75 @@ class RunTestFolderStep extends RunTestStep { @Override protected List run() throws Exception { - List 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 pkgFiles = scanPackages(testFolderPath, context, step.scanMode, step.recursiveScan) - final List 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 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 pkgFiles = scanPackages(testFolderPath, context, step.scanMode, step.recursiveScan) + final List 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 scanPackages(final String testFolder, final StepContext context, - ScanMode scanMode, boolean isRecursive) { + ScanMode scanMode, boolean isRecursive) + throws IOException, InterruptedException { List 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 { @@ -207,20 +209,15 @@ class RunTestFolderStep extends RunTestStep { } private static List scanProjects(final String testFolder, final StepContext context, - ScanMode scanMode, boolean isRecursive) { + ScanMode scanMode, boolean isRecursive) + throws IOException, InterruptedException { List 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 { diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStep.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStep.groovy index 66ca5d98..dae52bb5 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStep.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStep.groovy @@ -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.") } @@ -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 } /** @@ -251,13 +258,13 @@ 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.") } } @@ -265,8 +272,9 @@ class StartToolStep extends Step { /** * 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) @@ -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.") } } @@ -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.") } } } diff --git a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStep.groovy b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStep.groovy index f40c5dfa..7e514529 100644 --- a/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStep.groovy +++ b/src/main/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStep.groovy @@ -121,7 +121,7 @@ class StopToolStep extends Step { } @Override - Void call() { + Void call() throws IOException { String toolName = installation.getName() if (toolName) { listener.logger.println("Stopping ${toolName}...") @@ -132,8 +132,9 @@ class StopToolStep extends Step { listener.logger.println("${toolName} stopped successfully.") } else { throw new AbortException( - "Timeout of ${this.timeout} seconds exceeded for stopping ${toolName}!" + - "Please ensure that the tool is not already stopped.") + "Timeout of ${this.timeout} seconds exceeded for stopping ${toolName}! " + + "Please ensure that the tool is not already stopped or " + + "blocked by another process.") } } @@ -143,8 +144,9 @@ class StopToolStep extends Step { 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.") + "Timeout of ${this.timeout} seconds exceeded for stopping tracetronic tools! " + + "Please ensure that tracetronic tools are not already stopped or " + + "blocked by another process.") } } diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy index 1b420c24..38417a20 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunPackageStepIT.groovy @@ -234,4 +234,17 @@ class RunPackageStepIT extends IntegrationTestBase { jenkins.assertLogNotContains('ecu.test is busy', run) jenkins.assertLogContains("Execution has exceeded the configured timeout of 2 seconds", run) } + + def 'Run pipeline: package path does not exist'() { + given: + File tempDir = File.createTempDir() + tempDir.deleteOnExit() + String tempDirString = tempDir.getPath().replace('\\', '/') + WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') + job.setDefinition(new CpsFlowDefinition("node { ttRunPackage testCasePath: '${tempDirString}/foo/test.pkg' }", true)) + expect: + WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) + jenkins.assertLogContains("ecu.test package at ${tempDirString}/foo/test.pkg does not exist!" + + " Please ensure that the path is correctly set and it refers to the desired directory.", run) + } } diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy index 7adb3192..f52d1465 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunProjectStepIT.groovy @@ -152,4 +152,17 @@ class RunProjectStepIT extends IntegrationTestBase { jenkins.assertLogNotContains('ecu.test is busy', run) jenkins.assertLogContains('unauthorized', run) } + + def 'Run pipeline: ecu.test folder at path does not exist'() { + given: + File tempDir = File.createTempDir() + String nonExistentFolder = tempDir.getPath().replace('\\', '/') + "/foo" + WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') + job.setDefinition(new CpsFlowDefinition("node { ttRunProject testCasePath: '${nonExistentFolder}' }", true)) + expect: + WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) + jenkins.assertLogContains("ecu.test project at ${nonExistentFolder} does not exist! " + + "Please ensure that the path is correctly set and it refers to the desired directory.", run) + } + } diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy index 52da7536..68c870e0 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/RunTestFolderStepIT.groovy @@ -230,6 +230,30 @@ class RunTestFolderStepIT extends IntegrationTestBase { jenkins.assertLogContains("Executing project '${testProject.getAbsolutePath()}'", run) } + def 'Run pipeline: ecu.test folder at path does not exist'() { + given: + File tempDir = File.createTempDir() + String nonExistentFolder = tempDir.getPath().replace('\\', '/') + "/foo" + WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') + job.setDefinition(new CpsFlowDefinition("node { ttRunTestFolder testCasePath: '${nonExistentFolder}' }", true)) + expect: + WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) + jenkins.assertLogContains("ecu.test folder at ${nonExistentFolder} does not extist! " + + "Please ensure that the path is correctly set and it refers to the desired directory.", run) + } + + def 'Run pipeline: unsupported relative paths'() { + given: + String relativeFolder = "relative/path/to/folder" + WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') + job.setDefinition(new CpsFlowDefinition("node { ttRunTestFolder testCasePath: '${relativeFolder}' }", true)) + expect: + WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) + jenkins.assertLogContains("Unsupported relative paths for ecu.test folder '${relativeFolder}'! " + + "Please ensure that the path is correctly set and it refers to the desired directory. " + + "Consider using an absolute path instead.", run) + } + void setupTestFolder() { testProject = folder.newFile("test.prj") testPackage = folder.newFile("test.pkg") diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStepIT.groovy index 50989906..4689c5d3 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StartToolStepIT.groovy @@ -7,6 +7,7 @@ package de.tracetronic.jenkins.plugins.ecutestexecution.steps import de.tracetronic.jenkins.plugins.ecutestexecution.ETInstallation import de.tracetronic.jenkins.plugins.ecutestexecution.IntegrationTestBase +import de.tracetronic.jenkins.plugins.ecutestexecution.util.ProcessUtil import hudson.Functions import hudson.model.Result import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition @@ -153,4 +154,36 @@ class StartToolStepIT extends IntegrationTestBase { jenkins.assertLogNotContains('Stop tracetronic tool instances.', run) jenkins.assertLogContains('Starting ecu.test...', run) } + + def 'Run pipeline: Workspace directory does not exist'() { + given: + File tempDir = File.createTempDir() + tempDir.deleteOnExit() + String tempDirString = tempDir.getPath().replace('\\', '/') + WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') + job.setDefinition(new CpsFlowDefinition("node { ttStartTool toolName: 'ecu.test', " + + "workspaceDir: '${tempDirString}/foo', settingsDir: '${tempDirString}' }", true)) + expect: + WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) + jenkins.assertLogContains("ecu.test workspace directory at ${tempDirString}/foo does not exist! " + + "Please ensure that the path is correctly set and it refers to the desired directory.", run) + } + + def 'Run pipeline: Timeout exceeded'() { + given: + File tempDir = File.createTempDir() + tempDir.deleteOnExit() + String workspaceDir = tempDir.getPath().replace('\\', '/') + WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline') + job.setDefinition(new CpsFlowDefinition("node { ttStartTool toolName: 'ecu.test', " + + "workspaceDir: '${workspaceDir}', settingsDir: '${workspaceDir}' }", true)) + when: + GroovyMock(ProcessUtil, global: true) + ProcessUtil.killTTProcesses(_) >> false + then: + WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) + jenkins.assertLogContains("Timeout of 60 seconds exceeded for stopping tracetronic tools! " + + "Please ensure that tracetronic tools are not already stopped or " + + "blocked by another process.", run) + } } diff --git a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStepIT.groovy b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStepIT.groovy index 983915c8..63fa072c 100644 --- a/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStepIT.groovy +++ b/src/test/groovy/de/tracetronic/jenkins/plugins/ecutestexecution/steps/StopToolStepIT.groovy @@ -110,7 +110,9 @@ class StopToolStepIT extends IntegrationTestBase { ProcessUtil.killProcess(_, _) >> false then: WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) - jenkins.assertLogContains("Timeout of 30 seconds exceeded for stopping ${toolName}!", run) + jenkins.assertLogContains("Timeout of 30 seconds exceeded for stopping ${toolName}! " + + "Please ensure that the tool is not already stopped or " + + "blocked by another process.", run) where: toolName = 'ecu.test' } @@ -139,6 +141,8 @@ class StopToolStepIT extends IntegrationTestBase { ProcessUtil.killTTProcesses(_) >> false then: WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()) - jenkins.assertLogContains('Timeout of 30 seconds exceeded for stopping tracetronic tools!', run) + jenkins.assertLogContains("Timeout of 30 seconds exceeded for stopping tracetronic tools! " + + "Please ensure that tracetronic tools are not already stopped or " + + "blocked by another process.", run) } }