Skip to content

Commit

Permalink
JENKINS-53528 Do not excessively split tests
Browse files Browse the repository at this point in the history
Limit the number of splits to be at most the number of test classes
  • Loading branch information
agentgonzo committed Sep 12, 2018
1 parent 5ed529f commit bfe0f29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public CountDrivenParallelism(int size) {

@Override
public int calculate(List<TestClass> tests) {
return size;
// Don't split into 5 buckets if we only have 2 tests etc
return tests == null ?
size :
Math.min(size, tests.size());
}

@Symbol("count")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ public void findTestSplits() throws Exception {
}
}

@Test
public void testWeDoNotCreateMoreSplitsThanThereAreTests() throws Exception {
// The test report only has 2 classes, so we should only split into 2 test executors
TestResult testResult = new TestResult(0L, scanner, false);
testResult.tally();
when(action.getResult()).thenReturn(testResult);

CountDrivenParallelism parallelism = new CountDrivenParallelism(5);
List<InclusionExclusionPattern> splits = ParallelTestExecutor.findTestSplits(parallelism, build, listener, false, null, null, false);
assertEquals(2, splits.size());
for (InclusionExclusionPattern split : splits) {
assertFalse(split.isIncludes());
}
}

@Test
public void findTestSplitsInclusions() throws Exception {
TestResult testResult = new TestResult(0L, scanner, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="org.jenkinsci.plugins.parallel_test_executor.Test1" time="110.00" tests="20" errors="0" skipped="0" failures="0">
<testcase name="test1Case1" classname="org.jenkinsci.plugins.parallel_test_executor.Test1" time="1.00"/>
<testcase name="test1Case2" classname="org.jenkinsci.plugins.parallel_test_executor.Test1" time="2.00"/>
<testcase name="test1Case3" classname="org.jenkinsci.plugins.parallel_test_executor.Test2" time="3.00"/>
</testsuite>

0 comments on commit bfe0f29

Please sign in to comment.