Skip to content

Commit

Permalink
Merge pull request #284 from Vlatombe/parallel-branches-matching
Browse files Browse the repository at this point in the history
Parallel branch matching logging and testing
  • Loading branch information
jglick authored Mar 18, 2024
2 parents 764e365 + 3f8bd10 commit 81c8f8d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ static List<InclusionExclusionPattern> findTestSplits(Parallelism parallelism, @
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());

Check warning on line 211 in src/main/java/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 211 is not covered by tests
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,51 @@ public void splitTestsWithinStage() throws Exception {
jenkinsRule.assertLogContains("allSplits.size=1", b1);
jenkinsRule.assertLogContains("allSplits[0]: includes=false list=[]", b1);
WorkflowRun b2 = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0));
jenkinsRule.assertLogContains("Found stage \"first\" in ", b2);
jenkinsRule.assertLogContains("splits.size=2", b2);
jenkinsRule.assertLogContains("splits[0]: includes=false list=[two.java, two.class]", b2);
jenkinsRule.assertLogContains("splits[1]: includes=true list=[two.java, two.class]", b2);
jenkinsRule.assertLogContains("allSplits.size=2", b2);
jenkinsRule.assertLogContains("allSplits[0]: includes=false list=[one.java, one.class, two.java, two.class]", b2);
jenkinsRule.assertLogContains("allSplits[1]: includes=true list=[one.java, one.class, two.java, two.class]", b2);
}

@Test
public void splitTestsWithinParallelStage() throws Exception {
WorkflowJob p = jenkinsRule.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"def splits = splitTests parallelism: count(2), generateInclusions: true, stage: 'Branch: first'\n" +
"echo \"splits.size=${splits.size()}\"; for (int i = 0; i < splits.size(); i++) {\n" +
" def split = splits[i]; echo \"splits[${i}]: includes=${split.includes} list=${split.list}\"\n" +
"}\n" +
"def allSplits = splitTests parallelism: count(2), generateInclusions: true\n" +
"echo \"allSplits.size=${allSplits.size()}\"; for (int i = 0; i < allSplits.size(); i++) {\n" +
" def split = allSplits[i]; echo \"allSplits[${i}]: includes=${split.includes} list=${split.list}\"\n" +
"}\n" +
"def branches = [:]\n" +
"branches['first'] = {\n" +
" node {\n" +
" writeFile file: 'TEST-1.xml', text: '<testsuite name=\"one\"><testcase name=\"x\"/></testsuite>'\n" +
" writeFile file: 'TEST-2.xml', text: '<testsuite name=\"two\"><testcase name=\"y\"/></testsuite>'\n" +
" junit 'TEST-*.xml'\n" +
" }\n" +
"}\n" +
"branches['second'] = {\n" +
" node {\n" +
" writeFile file: 'TEST-3.xml', text: '<testsuite name=\"three\"><testcase name=\"a\"/></testsuite>'\n" +
" writeFile file: 'TEST-4.xml', text: '<testsuite name=\"four\"><testcase name=\"b\"/></testsuite>'\n" +
" junit 'TEST-*.xml'\n" +
" }\n" +
"}\n" +
"parallel branches\n"
, true));
WorkflowRun b1 = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0));
jenkinsRule.assertLogContains("splits.size=1", b1);
jenkinsRule.assertLogContains("splits[0]: includes=false list=[]", b1);
jenkinsRule.assertLogContains("allSplits.size=1", b1);
jenkinsRule.assertLogContains("allSplits[0]: includes=false list=[]", b1);
WorkflowRun b2 = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0));
jenkinsRule.assertLogContains("Found stage \"Branch: first\" in ", b2);
jenkinsRule.assertLogContains("splits.size=2", b2);
jenkinsRule.assertLogContains("splits[0]: includes=false list=[two.java, two.class]", b2);
jenkinsRule.assertLogContains("splits[1]: includes=true list=[two.java, two.class]", b2);
Expand Down

0 comments on commit 81c8f8d

Please sign in to comment.