Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #277 from jglick/diag-JENKINS-30395
Browse files Browse the repository at this point in the history
[JENKINS-30395] Preventing a recurrent ClosedByInterruptException in CI
  • Loading branch information
jglick committed Dec 18, 2015
2 parents 5bf7826 + 2876ca5 commit 3d85711
Show file tree
Hide file tree
Showing 40 changed files with 133 additions and 48 deletions.
Expand Up @@ -50,7 +50,7 @@

public class CpsFlowExecutionTest {

@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

private static WeakReference<ClassLoader> LOADER;
public static void register(Object o) {
Expand Down
Expand Up @@ -60,7 +60,7 @@

public class CpsScmFlowDefinitionTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

@Test public void basics() throws Exception {
Expand Down
Expand Up @@ -37,7 +37,7 @@
*/
public class DSLTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void overrideFunction() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down
Expand Up @@ -49,7 +49,7 @@
public class DynamicEnvironmentExpanderTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

@Issue("JENKINS-26163")
@Test public void dynamics() {
Expand Down
Expand Up @@ -36,7 +36,7 @@
*/
public class EnvWorkflowTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

/**
* Verifies if NODE_NAME environment variable is available on a slave node and on master.
Expand Down
Expand Up @@ -34,11 +34,19 @@
import hudson.slaves.SlaveComputer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.HudsonHomeLoader;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RestartableJenkinsRule;

/**
* Utilities that could be added to {@link JenkinsRule} in the future but are not yet available in our baseline version.
Expand Down Expand Up @@ -80,6 +88,61 @@ private static class SpecialEnvComputer extends SlaveComputer {
}
}

public static JenkinsRule workAroundJenkins30395() {
return new JenkinsRule() {
@Override public void before() throws Throwable {
if (Thread.interrupted()) {
System.err.println("was interrupted before start");
}
super.before();
}
};
}
public static RestartableJenkinsRule workAroundJenkins30395Restartable() {
return new RestartableJenkinsRule() {
private Description description;
private final List<Statement> steps = new ArrayList<Statement>();
private TemporaryFolder tmp = new TemporaryFolder();
private Object target;
@Override
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
this.description = Description.createTestDescription(
method.getMethod().getDeclaringClass(), method.getName(), method.getAnnotations());
this.target = target;
return tmp.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
home = tmp.newFolder();
base.evaluate();
run();
}
}, description);
}
public void addStep(final Statement step) {
steps.add(new Statement() {
@Override
public void evaluate() throws Throwable {
j.jenkins.getInjector().injectMembers(step);
j.jenkins.getInjector().injectMembers(target);
step.evaluate();
}
});
}
private void run() throws Throwable {
HudsonHomeLoader loader = new HudsonHomeLoader() {
@Override
public File allocate() throws Exception {
return home;
}
};
for (Statement step : steps) {
j = workAroundJenkins30395().with(loader);
j.apply(step,description).evaluate();
}
}
};
}

private JenkinsRuleExt() {}

}
Expand Up @@ -46,7 +46,7 @@
public abstract class SingleJobTestBase extends Assert {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

// currently executing workflow and its build
public WorkflowJob p;
Expand Down
Expand Up @@ -50,7 +50,7 @@
public class WorkflowRunRestartTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

@Issue("JENKINS-25550")
@Test public void hardKill() throws Exception {
Expand Down
Expand Up @@ -66,7 +66,7 @@
public class WorkflowRunTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down
Expand Up @@ -4,6 +4,7 @@
import static java.util.Arrays.asList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsThreadDump.ThreadInfo;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -19,8 +20,7 @@
public class CpsThreadDumpTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule
public JenkinsRule j = new JenkinsRule();
@Rule public JenkinsRule j = JenkinsRuleExt.workAroundJenkins30395();
private WorkflowJob p;

@Before
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.jvnet.hudson.test.RestartableJenkinsRule;
import javax.inject.Inject;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.JenkinsRule;
Expand All @@ -25,8 +26,8 @@
* @author Kohsuke Kawaguchi
*/
public class WorkflowLibRepositoryTest {
@Rule
public RestartableJenkinsRule story = new RestartableJenkinsRule();

@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

@Inject
Jenkins jenkins;
Expand Down
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.workflow.cps.steps;

import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -17,7 +18,7 @@
public class LoadStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test
public void basics() throws Exception {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import javax.inject.Inject;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand All @@ -20,8 +21,7 @@
* @author Kohsuke Kawaguchi
*/
public class RestartingLoadStepTest {
@Rule
public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

@Inject
Jenkins jenkins;
Expand Down
Expand Up @@ -12,13 +12,13 @@
import org.jvnet.hudson.test.JenkinsRule;

import java.util.Arrays;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;

/**
* @author Kohsuke Kawaguchi
*/
public class ArtifactArchiverStepTest extends Assert {
@Rule
public JenkinsRule j = new JenkinsRule();
@Rule public JenkinsRule j = JenkinsRuleExt.workAroundJenkins30395();

/**
* Archive and unarchive file
Expand Down
Expand Up @@ -26,6 +26,7 @@

import hudson.model.Result;
import jenkins.model.CauseOfInterruption;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -36,7 +37,7 @@

public class CatchErrorStepTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void specialStatus() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down
Expand Up @@ -30,6 +30,7 @@
import hudson.tasks.junit.TestResultAction;
import java.util.List;
import javax.mail.internet.InternetAddress;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -44,7 +45,7 @@
public class CoreStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void artifactArchiver() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down
Expand Up @@ -62,7 +62,7 @@
public class CoreWrapperStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

@Test public void useWrapper() throws Exception {
story.addStep(new Statement() {
Expand Down
Expand Up @@ -39,11 +39,11 @@

import hudson.FilePath;
import hudson.model.queue.QueueTaskFuture;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;

public class DeleteDirStepTest {

@Rule
public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test
public void testDeleteEmptyWorkspace() throws Exception {
Expand Down
Expand Up @@ -24,6 +24,7 @@

package org.jenkinsci.plugins.workflow.steps;

import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -38,7 +39,7 @@
public class EnvStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

@Test public void overriding() {
story.addStep(new Statement() {
Expand Down
Expand Up @@ -24,6 +24,7 @@

package org.jenkinsci.plugins.workflow.steps;

import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Test;
Expand All @@ -32,7 +33,7 @@

public class IsUnixStepTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down
Expand Up @@ -38,14 +38,14 @@
import javax.mail.Message;
import javax.mail.internet.MimeMultipart;
import java.io.IOException;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;

/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class MailStepTest {

@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();
@Rule public JenkinsRule jenkinsRule = JenkinsRuleExt.workAroundJenkins30395();

@Test
public void test_missing_subject() throws Exception {
Expand Down
Expand Up @@ -26,6 +26,7 @@

import hudson.Functions;
import java.io.File;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -40,7 +41,7 @@
public class PushdStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();
@Rule public RestartableJenkinsRule story = JenkinsRuleExt.workAroundJenkins30395Restartable();

private String pwdStep() {
return Functions.isWindows() ? "bat 'cd'" : "sh 'pwd'";
Expand Down
Expand Up @@ -24,6 +24,7 @@

package org.jenkinsci.plugins.workflow.steps;

import org.jenkinsci.plugins.workflow.JenkinsRuleExt;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Test;
Expand All @@ -32,7 +33,7 @@

public class PwdStepTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down
Expand Up @@ -25,6 +25,7 @@
package org.jenkinsci.plugins.workflow.steps;

import hudson.Functions;
import org.jenkinsci.plugins.workflow.JenkinsRuleExt;

import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand All @@ -35,7 +36,7 @@

public class ReadWriteFileStepTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public JenkinsRule r = JenkinsRuleExt.workAroundJenkins30395();

@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down

0 comments on commit 3d85711

Please sign in to comment.