Skip to content

Commit

Permalink
In some cases previous test result per stage can't be resolved, addin…
Browse files Browse the repository at this point in the history
…g more diagnostics
  • Loading branch information
Vlatombe committed Dec 20, 2024
1 parent 839b05e commit 1063707
Showing 1 changed file with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,14 @@ static List<InclusionExclusionPattern> findTestSplits(Parallelism parallelism, @
TestResult tr = findPreviousTestResult(build, listener);
Map<String/*fully qualified class name*/, TestEntity> data = new TreeMap<>();
if (tr != null) {
Run<?,?> prevRun = tr.getRun();
if (prevRun instanceof FlowExecutionOwner.Executable && stageName != null) {
FlowExecutionOwner owner = ((FlowExecutionOwner.Executable)prevRun).asFlowExecutionOwner();
if (owner != null) {
FlowExecution execution = owner.getOrNull();
if (execution != null) {
DepthFirstScanner scanner = new DepthFirstScanner();
FlowNode stageId = scanner.findFirstMatch(execution, new StageNamePredicate(stageName));
if (stageId != null) {
listener.getLogger().println("Found stage \"" + stageName + "\" in " + prevRun.getFullDisplayName());
tr = ((hudson.tasks.junit.TestResult) tr).getResultForPipelineBlock(stageId.getId());
} else {
listener.getLogger().println("No stage \"" + stageName + "\" found in " + prevRun.getFullDisplayName());
}
}
}
}
tr = mayFilterByStageName(tr, stageName, listener);
collect(tr, data, testMode);
} else {
listener.getLogger().println("No record available, try to find test classes");
data = testMode.estimate(workspace, listener);
if(data.isEmpty()) {
listener.getLogger().println("No test classes was found, so executing everything in one place");
return Collections.singletonList(new InclusionExclusionPattern(Collections.<String>emptyList(), false));
return List.of(new InclusionExclusionPattern(List.of(), false));
}
}

Expand Down Expand Up @@ -148,6 +132,42 @@ static List<InclusionExclusionPattern> findTestSplits(Parallelism parallelism, @
return r;
}

@NonNull
private static TestResult mayFilterByStageName(@NonNull TestResult tr, @CheckForNull String stageName, @NonNull TaskListener listener) {
Run<?,?> run = tr.getRun();
if (stageName != null) {
listener.getLogger().println("Looking for stage \"" + stageName + "\" in " + run.getFullDisplayName());
FlowExecution execution = resolveFlowExecution(run, listener);
if (execution != null) {

Check warning on line 141 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 141 is only partially covered, one branch is missing
FlowNode stageId = new DepthFirstScanner().findFirstMatch(execution, new StageNamePredicate(stageName));
if (stageId != null) {

Check warning on line 143 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 143 is only partially covered, one branch is missing
listener.getLogger().println("Found stage \"" + stageName + "\" in " + run.getFullDisplayName());
tr = ((hudson.tasks.junit.TestResult) tr).getResultForPipelineBlock(stageId.getId());
} else {
listener.getLogger().println("No stage \"" + stageName + "\" found in " + run.getFullDisplayName());

Check warning on line 147 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 147 is not covered by tests
}
} else {
listener.getLogger().println("No flow execution found in " + run.getFullDisplayName());

Check warning on line 150 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 150 is not covered by tests
}
}
return tr;
}

@CheckForNull
private static FlowExecution resolveFlowExecution(Run<?, ?> prevRun, TaskListener listener) {
if (prevRun instanceof FlowExecutionOwner.Executable) {

Check warning on line 158 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 158 is only partially covered, one branch is missing
FlowExecutionOwner owner = ((FlowExecutionOwner.Executable) prevRun).asFlowExecutionOwner();
if (owner != null) {

Check warning on line 160 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 160 is only partially covered, one branch is missing
return owner.getOrNull();
} else {
listener.getLogger().println("No flow execution owner found in " + prevRun.getFullDisplayName());
}
} else {
listener.getLogger().println("Previous run doesn't have the expected type: " + prevRun);
}
return null;
}

private static long pow(long l) {
return l * l;
}
Expand Down Expand Up @@ -183,7 +203,7 @@ private static TestResult findPreviousTestResult(Run<?, ?> b, TaskListener liste
if (head instanceof ChangeRequestSCMHead) {
SCMHead target = ((ChangeRequestSCMHead) head).getTarget();
Item targetBranch = project.getParent().getItem(target.getName());
if (targetBranch != null && targetBranch instanceof Job) {
if (targetBranch instanceof Job) {

Check warning on line 206 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/Splitter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 163-206 are not covered by tests
result = getTestResult(project, ((Job<?, ?>) targetBranch).getLastBuild(), listener);
}
}
Expand Down

0 comments on commit 1063707

Please sign in to comment.