|
48 | 48 | import hudson.slaves.NodeProperty; |
49 | 49 | import hudson.slaves.OfflineCause; |
50 | 50 | import hudson.slaves.RetentionStrategy; |
| 51 | +import hudson.slaves.WorkspaceList; |
51 | 52 | import hudson.util.StreamCopyThread; |
52 | 53 | import java.io.File; |
53 | 54 | import java.io.FileOutputStream; |
|
94 | 95 | import static org.junit.Assert.*; |
95 | 96 | import org.junit.Assume; |
96 | 97 | import org.junit.ClassRule; |
| 98 | +import org.junit.Ignore; |
97 | 99 | import org.junit.Rule; |
98 | 100 | import org.junit.Test; |
99 | 101 | import org.junit.rules.TemporaryFolder; |
@@ -322,6 +324,84 @@ private void startJnlpProc() throws Exception { |
322 | 324 | }); |
323 | 325 | } |
324 | 326 |
|
| 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 | + |
325 | 405 | @Test public void buildShellScriptQuick() throws Exception { |
326 | 406 | story.addStep(new Statement() { |
327 | 407 | @Override public void evaluate() throws Throwable { |
|
0 commit comments