-
-
Notifications
You must be signed in to change notification settings - Fork 57
In some cases previous test result per stage can't be resolved, adding more diagnostics #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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) { | ||
| listener.getLogger().println("Looking for stage \"" + stageName + "\" in " + run.getFullDisplayName()); | ||
| FlowExecution execution = resolveFlowExecution(run, listener); | ||
| if (execution != null) { | ||
| FlowNode stageId = new DepthFirstScanner().findFirstMatch(execution, new StageNamePredicate(stageName)); | ||
| if (stageId != null) { | ||
| listener.getLogger().println("Found stage \"" + stageName + "\" in " + run.getFullDisplayName()); | ||
| tr = ((hudson.tasks.junit.TestResult) tr).getResultForPipelineBlock(stageId.getId()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
| } | ||
| } else { | ||
| listener.getLogger().println("No flow execution found in " + run.getFullDisplayName()); | ||
| } | ||
| } | ||
| return tr; | ||
| } | ||
|
|
||
| @CheckForNull | ||
| private static FlowExecution resolveFlowExecution(Run<?, ?> prevRun, TaskListener listener) { | ||
| if (prevRun instanceof FlowExecutionOwner.Executable) { | ||
| FlowExecutionOwner owner = ((FlowExecutionOwner.Executable) prevRun).asFlowExecutionOwner(); | ||
|
Comment on lines
+158
to
+159
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (reminder to do #310) |
||
| if (owner != null) { | ||
| 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) { | ||
| result = getTestResult(project, ((Job<?, ?>) targetBranch).getLastBuild(), listener); | ||
|
Comment on lines
+206
to
207
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here too |
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.