Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,14 @@
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,42 +132,78 @@
return r;
}

@NonNull
private static TestResult mayFilterByStageName(@NonNull TestResult tr, @CheckForNull String stageName, @NonNull TaskListener listener) {
Run<?,?> run = tr.getRun();
if (stageName != null) {
Comment on lines +137 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Run<?,?> run = tr.getRun();
if (stageName != null) {
if (stageName != null) {
Run<?,?> run = tr.getRun();

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cast need to be checked?

} 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();
Comment on lines +158 to +159
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(reminder to do #310)

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

/**
* Visits the structure inside {@link hudson.tasks.test.TestResult}.
*/
private static void collect(TestResult r, Map<String, TestEntity> data, TestMode testMode) {
var queue = new ArrayDeque<TestResult>();
queue.push(r);
while (!queue.isEmpty()) {
var current = queue.pop();
if (current instanceof ClassResult) {
var classResult = (ClassResult) current;
LOGGER.log(Level.FINE, () -> "Retrieving test entities from " + classResult.getFullName());
data.putAll(testMode.getTestEntitiesMap(classResult));
} else if (current instanceof TabulatedResult) {
LOGGER.log(Level.FINE, () -> "Considering children of " + current.getFullName());
queue.addAll(((TabulatedResult) current).getChildren());
} else {
LOGGER.log(Level.FINE, () -> "Ignoring " + current.getFullName());
}
}
}

private static TestResult findPreviousTestResult(Run<?, ?> b, TaskListener listener) {
Job<?, ?> project = b.getParent();
// Look for test results starting with the previous build
TestResult result = getTestResult(project, b.getPreviousBuild(), listener);
if (result == null) {
// Look for test results from the target branch builds if this is a change request.
SCMHead head = SCMHead.HeadByItem.findHead(project);
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);
Comment on lines +206 to 207
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

}
}
Expand Down
Loading