return; final Throwable death = new FlowInterruptedException(Result.ABORTED, new ExceededTimeout()); body.cancel(new ExceededTimeout()); forcible = true; timeout = GRACE_PERIOD;
@Test public void interruptedTest() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("node {\n" + "echo 'First message'\n" + "try { syncnonblocking 'wait' } catch(InterruptedException e) { echo 'Interrupted!' }\n" + "echo 'Second message'\n" + "}", true)); WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get(); // Wait for syncnonblocking to be started System.out.println("Waiting to syncnonblocking to start..."); SynchronousNonBlockingStep.waitForStart("wait", b); // At this point syncnonblocking is waiting for an interruption // Let's force a call to stop. This will try to send an interruption to the run Thread b.getExecutor().interrupt(); System.out.println("Looking for interruption received log message"); j.waitForMessage("Interrupted!", b); j.waitForCompletion(b); j.assertBuildStatus(Result.ABORTED, b); // Also check that timeouts produce the right status. p.setDefinition(new CpsFlowDefinition("timeout(time: 1, unit: 'SECONDS') {syncnonblocking 'wait2'}", true)); j.assertLogContains(new TimeoutStepExecution.ExceededTimeout().getShortDescription(), j.assertBuildStatus(Result.ABORTED, p.scheduleBuild2(0))); }