Skip to content
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

[JENKINS-49707] Tests of ErrorCondition across restarts #195

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.332.x</artifactId>
<version>1370.vfa_e23fe119c3</version>
<version>1438.v6a_2c29d73f82</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -125,12 +125,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>1164.v2334ddcf48d0</version> <!-- TODO until in BOM -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<scope>test</scope>
<version>1235.vb_9618c5d0471</version> <!-- TODO https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/180 -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -182,11 +177,6 @@
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ansicolor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.Map;
import java.util.Set;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import jenkins.tasks.SimpleBuildWrapper;
import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -50,6 +52,8 @@
*/
public class CoreWrapperStep extends Step {

private static final Logger LOGGER = Logger.getLogger(CoreWrapperStep.class.getName());

private final SimpleBuildWrapper delegate;

@DataBoundConstructor public CoreWrapperStep(SimpleBuildWrapper delegate) {
Expand Down Expand Up @@ -177,15 +181,26 @@ private static final class Callback extends BodyExecutionCallback.TailCall {
assert run != null;
final TaskListener listener = context.get(TaskListener.class);
assert listener != null;
final FilePath workspace = context.get(FilePath.class);
final Launcher launcher = context.get(Launcher.class);
FilePath workspace;
Launcher launcher;
if (disposer.requiresWorkspace()) {
workspace = context.get(FilePath.class);
if (workspace == null) {
throw new MissingContextVariableException(FilePath.class);
}
launcher = context.get(Launcher.class);
if (launcher == null) {
throw new MissingContextVariableException(Launcher.class);
}
} else {
try {
workspace = context.get(FilePath.class);
launcher = context.get(Launcher.class);
} catch (IOException | InterruptedException x) {
LOGGER.log(Level.FINE, null, x);
workspace = null;
launcher = null;
}
}
// always pass the workspace context when available, even when it is not strictly required
if (workspace != null && launcher != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.Map;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.logging.Level;
import jenkins.tasks.SimpleBuildWrapper;
import org.hamcrest.Matchers;
import org.jenkinsci.Symbol;
Expand All @@ -79,15 +80,19 @@
import org.kohsuke.stapler.DataBoundConstructor;

import static org.hamcrest.MatcherAssert.assertThat;
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepDynamicContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.jvnet.hudson.test.LoggerRule;

public class CoreWrapperStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsSessionRule sessions = new JenkinsSessionRule();
@Rule public LoggerRule logging = new LoggerRule();

@Test public void useWrapper() throws Throwable {
logging.record(ExecutorStepDynamicContext.class, Level.FINE);
sessions.then(j -> {
new SnippetizerTester(j).assertRoundTrip(new CoreWrapperStep(new MockWrapper()), "mock {\n // some block\n}");
Map<String,String> slaveEnv = new HashMap<>();
Expand Down Expand Up @@ -257,8 +262,7 @@ private static class UpcaseFilter extends ConsoleLogFilter implements Serializab
* @see <a href="https://github.com/jenkinsci/jenkins/pull/1553/files#r23784822">explanation in core PR 1553</a>
*/
public static Slave createSpecialEnvSlave(JenkinsRule rule, String nodeName, @CheckForNull String labels, Map<String,String> env) throws Exception {
@SuppressWarnings("deprecation") // keep consistency with original signature rather than force the caller to pass in a TemporaryFolder rule
File remoteFS = rule.createTmpDir();
File remoteFS = new File(rule.jenkins.getRootDir(), "agent-work-dirs/" + nodeName);
SpecialEnvSlave slave = new SpecialEnvSlave(remoteFS, rule.createComputerLauncher(/* yes null */null), nodeName, labels != null ? labels : "", env);
rule.jenkins.addNode(slave);
return slave;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class PushdStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsSessionRule sessions = new JenkinsSessionRule();
@Rule public LoggerRule logging = new LoggerRule().record(FilePathDynamicContext.class, Level.FINE);
@Rule public LoggerRule logging = new LoggerRule().recordPackage(FilePathDynamicContext.class, Level.FINE);
// logging.recordPackage(FilePathPickle.class, Level.FINE);

@Test public void basics() throws Throwable {
sessions.then(j -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
Expand Down Expand Up @@ -151,7 +150,6 @@ public static final class HangStep extends Step {
}
}

@Ignore("TODO pending https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/180")
@Issue("JENKINS-49707")
@Test public void retryNewStepAcrossRestarts() throws Throwable {
logging.record(DurableTaskStep.class, Level.FINE).record(FileMonitoringTask.class, Level.FINE).record(ExecutorStepExecution.class, Level.FINE);
Expand Down Expand Up @@ -185,7 +183,6 @@ public static final class HangStep extends Step {
});
}

@Ignore("TODO pending https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/180")
@Issue({"JENKINS-49707", "JENKINS-30383"})
@Test public void retryNodeBlockSynchAcrossRestarts() throws Throwable {
logging.record(ExecutorStepExecution.class, Level.FINE).record(FlowExecutionList.class, Level.FINE);
Expand Down