Skip to content

Commit

Permalink
Report the state of all report generators (report generations) (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-marcel authored Mar 6, 2024
1 parent 46d5f07 commit 89f14e5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class GenerateReportsStep extends Step {
return settings.collectEntries { setting -> [setting.name, setting.value] }
}

static class Execution extends SynchronousNonBlockingStepExecution<GenerationResult> {
static class Execution extends SynchronousNonBlockingStepExecution<List<GenerationResult>> {

private static final long serialVersionUID = 1L

Expand All @@ -97,7 +97,7 @@ class GenerateReportsStep extends Step {
}

@Override
protected GenerationResult run() throws Exception {
protected List<GenerationResult> run() throws Exception {
List<AdditionalSetting> expSettings = expandSettings(step.additionalSettings, context.get(EnvVars.class))
Map<String, String> expSettingsMap = toSettingsMap(expSettings)

Expand All @@ -108,12 +108,12 @@ class GenerateReportsStep extends Step {
} catch (Exception e) {
context.get(TaskListener.class).error(e.message)
context.get(Run.class).setResult(Result.FAILURE)
return new GenerationResult("A problem occured during the report generation. See caused exception for more details.", "", null)
return [ new GenerationResult("A problem occured during the report generation. See caused exception for more details.", "", null) ]
}
}
}

private static final class ExecutionCallable extends MasterToSlaveCallable<GenerationResult, IOException> {
private static final class ExecutionCallable extends MasterToSlaveCallable<List<GenerationResult>, IOException> {

private static final long serialVersionUID = 1L

Expand All @@ -134,8 +134,8 @@ class GenerateReportsStep extends Step {
}

@Override
GenerationResult call() throws IOException {
GenerationResult result = null
List<GenerationResult> call() throws IOException {
List<GenerationResult> result = []
RestApiClient apiClient = RestApiClientFactory.getRestApiClient(envVars.get('ET_API_HOSTNAME'), envVars.get('ET_API_PORT'))

ReportGenerationOrder generationOrder = new ReportGenerationOrder(generatorName, additionalSettings)
Expand All @@ -147,8 +147,13 @@ class GenerateReportsStep extends Step {

reportIds.each { reportId ->
listener.logger.println("- Generating ${this.generatorName} report format for report id ${reportId}...")
result = apiClient.generateReport(reportId, generationOrder)
listener.logger.println(result.toString())
GenerationResult generationResult = apiClient.generateReport(reportId, generationOrder)
String log = " -> ${generationResult.generationResult}"
if (!generationResult.generationMessage.isEmpty()) {
log += " (${generationResult.generationMessage})"
}
listener.logger.println(log)
result.add(generationResult)
}

listener.logger.println("${this.generatorName} reports generated successfully.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class UploadReportsStep extends Step {
return settings.collectEntries { setting -> [setting.name, setting.value] }
}

static class Execution extends SynchronousNonBlockingStepExecution<UploadResult> {
static class Execution extends SynchronousNonBlockingStepExecution<List<UploadResult>> {

private static final long serialVersionUID = 1L

Expand All @@ -144,7 +144,7 @@ class UploadReportsStep extends Step {
}

@Override
protected UploadResult run() throws Exception {
protected List<UploadResult> run() throws Exception {
List<AdditionalSetting> expSettings = expandSettings(step.additionalSettings, context.get(EnvVars.class))
Map<String, String> expSettingsMap = toSettingsMap(expSettings)

Expand All @@ -161,9 +161,9 @@ class UploadReportsStep extends Step {
} catch (Exception e) {
context.get(TaskListener.class).error(e.message)
context.get(Run.class).setResult(Result.FAILURE)
return new UploadResult("Report upload failed",
return [ new UploadResult("Report upload failed",
"A problem occured during the report upload. See caused exception for more details.",
null)
null) ]
}

}
Expand All @@ -176,7 +176,7 @@ class UploadReportsStep extends Step {
}
}

private static final class ExecutionCallable extends MasterToSlaveCallable<UploadResult, IOException> {
private static final class ExecutionCallable extends MasterToSlaveCallable<List<UploadResult>, IOException> {

private static final long serialVersionUID = 1L

Expand All @@ -203,8 +203,8 @@ class UploadReportsStep extends Step {
}

@Override
UploadResult call() throws IOException {
UploadResult result = null
List<UploadResult> call() throws IOException {
List<UploadResult> result = []
RestApiClient apiClient = RestApiClientFactory.getRestApiClient(envVars.get('ET_API_HOSTNAME'), envVars.get('ET_API_PORT'))

TGUploadOrder uploadOrder = new TGUploadOrder(testGuideUrl,authKey, projectId, useSettingsFromServer, additionalSettings)
Expand All @@ -214,18 +214,26 @@ class UploadReportsStep extends Step {
reportIds = apiClient.getAllReportIds()
}

String status = 'successful'
Integer cntReports = reportIds.size()
Integer cntStable = 0

reportIds.each { reportId ->
listener.logger.println("- Uploading ATX report for report id ${reportId}...")

result = apiClient.uploadReport(reportId, uploadOrder)
if (result.reportLink == null || result.reportLink.isEmpty()) {
status = 'unstable. Please check pipeline and test.guide configuration.'
UploadResult uploadResult = apiClient.uploadReport(reportId, uploadOrder)
if (uploadResult.reportLink != null && !uploadResult.reportLink.isEmpty()) {
cntStable += 1
}
listener.logger.println(result.toString())
listener.logger.println(" -> ${uploadResult.uploadMessage}")

result.add(uploadResult)
}

listener.logger.println("Report upload ${status}")
if ( cntReports == cntStable) {
listener.logger.println("Report upload(s) successful")
} else {
listener.logger.println("Report upload(s) unstable. Please see the logging of the uploads.")
}

return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ abstract class ETContainerTest extends ContainerTest {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttRunPackage testCasePath: 'test.pkg'
ttRunProject testCasePath: 'test.prj'
ttGenerateReports generatorName: 'HTML', additionalSettings: [[name: 'javascript', value: 'False']]
}
def generationReports = ttGenerateReports generatorName: 'HTML', additionalSettings: [[name: 'javascript', value: 'False']]
echo "\${generationReports.reportOutputDir}"
echo "size of returned array: \${generationReports.size()}"
}
}
""".stripIndent()
WorkflowJob job = jenkins.createProject(WorkflowJob.class, "pipeline")
Expand All @@ -226,8 +228,9 @@ abstract class ETContainerTest extends ContainerTest {
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test and upload completion"
StringUtils.countMatches(jenkins.getLog(run), "result: FINISHED") == 2
StringUtils.countMatches(jenkins.getLog(run), "reportOutputDir: ${ET_WS_PATH}/TestReports/test_") == 2
StringUtils.countMatches(jenkins.getLog(run), "Generating HTML report format for report id") == 2
StringUtils.countMatches(jenkins.getLog(run), "-> FINISHED") == 2
StringUtils.contains(jenkins.getLog(run), "size of returned array: 2")
}

def "Generate report format for a specific test report"() {
Expand All @@ -248,7 +251,6 @@ abstract class ETContainerTest extends ContainerTest {
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test and upload completion"
StringUtils.countMatches(jenkins.getLog(run), "result: FINISHED") == 1
StringUtils.countMatches(jenkins.getLog(run), "reportOutputDir: ${ET_WS_PATH}/TestReports/test_") == 1
StringUtils.countMatches(jenkins.getLog(run), "-> FINISHED") == 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ class TGContainerTest extends ContainerTest {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttRunPackage testCasePath: 'test.pkg'
ttRunProject testCasePath: 'test.prj'
ttUploadReports testGuideUrl: 'http://${TG_ALIAS}:${TG_PORT}',
def uploadReports = ttUploadReports testGuideUrl: 'http://${TG_ALIAS}:${TG_PORT}',
credentialsId: 'authKey', useSettingsFromServer: false
echo "size of returned array: \${uploadReports.size()}"
}
}
""".stripIndent()
Expand All @@ -95,7 +96,8 @@ class TGContainerTest extends ContainerTest {
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test and upload completion"
StringUtils.countMatches(jenkins.getLog(run), "result: FINISHED") == 2
StringUtils.countMatches(jenkins.getLog(run), "result: SUCCESS") == 2
StringUtils.contains(jenkins.getLog(run), "size of returned array: 2")
}

def "Upload a specific test report"() {
Expand All @@ -119,7 +121,8 @@ class TGContainerTest extends ContainerTest {
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test and upload completion"
StringUtils.countMatches(jenkins.getLog(run), "result: FINISHED") == 1
StringUtils.countMatches(jenkins.getLog(run), "-> Uploaded successfully") == 1
StringUtils.countMatches(jenkins.getLog(run), "Report upload(s) successful") == 1
}

def "Upload an invalid test report"() {
Expand Down Expand Up @@ -170,8 +173,9 @@ class TGContainerTest extends ContainerTest {
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test but upload failed"
StringUtils.countMatches(jenkins.getLog(run), "ERROR") == 2
StringUtils.countMatches(jenkins.getLog(run), "Report upload for") == 2
StringUtils.countMatches(jenkins.getLog(run), "failed") == 2
StringUtils.countMatches(jenkins.getLog(run),
"Report upload unstable. Please check pipeline and test.guide configuration.") == 1
"Report upload(s) unstable. Please see the logging of the uploads.") == 1
}
}

0 comments on commit 89f14e5

Please sign in to comment.