Skip to content

Commit

Permalink
Merge pull request #37 from raul-arabaolaza/JENKINS-53172
Browse files Browse the repository at this point in the history
[JENKINS-53172] Make sure the reference build is not running
  • Loading branch information
abayer committed Aug 30, 2018
2 parents a591078 + 915ddf5 commit d6b35d1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pom.xml
Expand Up @@ -119,5 +119,17 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-milestone-step</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.6wind.jenkins</groupId>
<artifactId>lockable-resources</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -311,7 +311,7 @@ private static TestResult findPreviousTestResult(Run<?, ?> b, TaskListener liste
for (int i = 0; i < NUMBER_OF_BUILDS_TO_SEARCH; i++) {// limit the search to a small number to avoid loading too much
b = b.getPreviousBuild();
if (b == null) break;
if(!RESULTS_OF_BUILDS_TO_CONSIDER.contains(b.getResult())) continue;
if(!RESULTS_OF_BUILDS_TO_CONSIDER.contains(b.getResult()) || b.isBuilding()) continue;

AbstractTestResultAction tra = b.getAction(AbstractTestResultAction.class);
if (tra == null) continue;
Expand Down
@@ -1,6 +1,11 @@
package org.jenkinsci.plugins.parallel_test_executor;

import hudson.model.FreeStyleProject;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.StringParameterDefinition;
import hudson.model.StringParameterValue;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand Down Expand Up @@ -58,6 +63,41 @@ public void workflowGenerateInclusions() throws Exception {
jenkinsRule.assertLogContains("splits[1]: includes=true list=[two.java, two.class]", b2);
}

@Test
@Issue("JENKINS-53172")
public void workflowDoesNotGenerateInclusionsFromRunningBuild() throws Exception {
WorkflowJob p = jenkinsRule.jenkins.createProject(WorkflowJob.class, "p");
ParameterDefinition sleepDef = new StringParameterDefinition("SLEEP", "100", "");
ParametersDefinitionProperty sleepParamsDef = new ParametersDefinitionProperty(sleepDef);
p.addProperty(sleepParamsDef);
/* We need to wait for first build to generate test result before calling splitTests in the second build, So
* instead of trying to use a quiet period, which is not deterministic and will introduce potential flakiness,
* we use the existing locking and milestone facilities in pipeline to make sure that
* a) The second run waits until the first one has generated tests results by using a lock
* b) Once the second build finish the previous one is killed by using milestones
*/
p.setDefinition(new CpsFlowDefinition(
"lock('test-results') {\n" +
" def splits = splitTests parallelism: count(2), generateInclusions: true\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" +
" node {\n" +
" writeFile file: 'TEST-1.xml', text: '<testsuite name=\"one\"><testcase name=\"x\" failures=\"1\"/></testsuite>'\n" +
" writeFile file: 'TEST-2.xml', text: '<testsuite name=\"two\"><testcase name=\"y\"/></testsuite>'\n" +
" junit 'TEST-*.xml'\n" +
" currentBuild.result = 'UNSTABLE'\n" + // Needed due to https://issues.jenkins-ci.org/browse/JENKINS-48178
" }\n" +
"}\n" +
"milestone 1\n" +
"sleep time: Integer.valueOf(params.SLEEP), unit: 'SECONDS'\n" +
"milestone 2", true));
WorkflowRun b1 = p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("SLEEP", "100"))).waitForStart();
jenkinsRule.waitForMessage("Lock acquired on", b1);
WorkflowRun b2 = p.scheduleBuild2(0, new ParametersAction(new StringParameterValue("SLEEP", "0"))).get();
jenkinsRule.assertLogContains("splits.size=1", b2);
}

@Issue("JENKINS-27395")
@Test
public void splitTestsWithinStage() throws Exception {
Expand Down

0 comments on commit d6b35d1

Please sign in to comment.