Skip to content

Commit 4d61eee

Browse files
authored
Merge pull request #70 from basil/JENKINS-41854
Test cases for JENKINS-41854
2 parents 9336a7b + a11acf6 commit 4d61eee

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/test/java/org/jenkinsci/plugins/workflow/support/steps/ExecutorStepTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import hudson.slaves.NodeProperty;
4949
import hudson.slaves.OfflineCause;
5050
import hudson.slaves.RetentionStrategy;
51+
import hudson.slaves.WorkspaceList;
5152
import hudson.util.StreamCopyThread;
5253
import java.io.File;
5354
import java.io.FileOutputStream;
@@ -94,6 +95,7 @@
9495
import static org.junit.Assert.*;
9596
import org.junit.Assume;
9697
import org.junit.ClassRule;
98+
import org.junit.Ignore;
9799
import org.junit.Rule;
98100
import org.junit.Test;
99101
import org.junit.rules.TemporaryFolder;
@@ -322,6 +324,84 @@ private void startJnlpProc() throws Exception {
322324
});
323325
}
324326

327+
@Ignore("TODO currently fails with: hudson.remoting.RequestAbortedException: java.nio.channels.ClosedChannelException")
328+
@Issue("JENKINS-41854")
329+
@Test
330+
public void contextualizeFreshFilePathAfterAgentReconnection() throws Exception {
331+
Assume.assumeFalse("TODO not sure how to write a corresponding batch script", Functions.isWindows());
332+
story.addStep(new Statement() {
333+
@SuppressWarnings("SleepWhileInLoop")
334+
@Override
335+
public void evaluate() throws Throwable {
336+
Logger LOGGER = Logger.getLogger(DurableTaskStep.class.getName());
337+
LOGGER.setLevel(Level.FINE);
338+
Handler handler = new ConsoleHandler();
339+
handler.setLevel(Level.ALL);
340+
LOGGER.addHandler(handler);
341+
DumbSlave s = new DumbSlave("dumbo", "dummy", tmp.getRoot().getAbsolutePath(), "1", Node.Mode.NORMAL, "", new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList());
342+
story.j.jenkins.addNode(s);
343+
startJnlpProc();
344+
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "demo");
345+
File f1 = new File(story.j.jenkins.getRootDir(), "f1");
346+
File f2 = new File(story.j.jenkins.getRootDir(), "f2");
347+
new FileOutputStream(f1).close();
348+
p.setDefinition(new CpsFlowDefinition(
349+
"node('dumbo') {\n" +
350+
" sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" +
351+
" sh 'echo Back again'\n" +
352+
" echo 'OK, done'\n" +
353+
"}", true));
354+
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
355+
while (!f2.isFile()) {
356+
Thread.sleep(100);
357+
}
358+
assertTrue(b.isBuilding());
359+
Computer computer = s.toComputer();
360+
assertNotNull(computer);
361+
FlowGraphWalker walker = new FlowGraphWalker(b.getExecution());
362+
List<WorkspaceAction> actions = new ArrayList<>();
363+
for (FlowNode node : walker) {
364+
WorkspaceAction action = node.getAction(WorkspaceAction.class);
365+
if (action != null) {
366+
actions.add(action);
367+
}
368+
}
369+
assertEquals(1, actions.size());
370+
String workspacePath = actions.get(0).getWorkspace().getRemote();
371+
assertWorkspaceLocked(computer, workspacePath);
372+
killJnlpProc();
373+
while (computer.isOnline()) {
374+
Thread.sleep(100);
375+
}
376+
startJnlpProc();
377+
while (computer.isOffline()) {
378+
Thread.sleep(100);
379+
}
380+
assertWorkspaceLocked(computer, workspacePath);
381+
assertTrue(f2.isFile());
382+
assertTrue(f1.delete());
383+
while (f2.isFile()) {
384+
Thread.sleep(100);
385+
}
386+
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
387+
story.j.assertLogContains("finished waiting", b);
388+
story.j.assertLogContains("Back again", b);
389+
story.j.assertLogContains("OK, done", b);
390+
killJnlpProc();
391+
}
392+
});
393+
}
394+
395+
private static void assertWorkspaceLocked(Computer computer, String workspacePath) throws InterruptedException {
396+
FilePath proposed = new FilePath(computer.getChannel(), workspacePath);
397+
WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(proposed);
398+
try {
399+
assertNotEquals(workspacePath, lease.path.getRemote());
400+
} finally {
401+
lease.release();
402+
}
403+
}
404+
325405
@Test public void buildShellScriptQuick() throws Exception {
326406
story.addStep(new Statement() {
327407
@Override public void evaluate() throws Throwable {

0 commit comments

Comments
 (0)