|
33 | 33 | import static org.hamcrest.Matchers.equalTo; |
34 | 34 | import static org.hamcrest.Matchers.hasItem; |
35 | 35 | import static org.hamcrest.Matchers.not; |
| 36 | +import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException; |
36 | 37 |
|
37 | 38 | public class CpsStepContextTest { |
38 | 39 | @Rule |
@@ -82,19 +83,6 @@ public void executionStartExceptionNotLeakClosures() throws Exception { |
82 | 83 | assertThat(logger.getMessages(), not(hasItem(containsString("Stale closure")))); |
83 | 84 | } |
84 | 85 |
|
85 | | - @Issue("JENKINS-75067") |
86 | | - @Test |
87 | | - public void executionWithBodyRunningSyncNotLeakClosures() throws Exception { |
88 | | - logger.record(CpsThreadGroup.class, Level.WARNING).capture(10); |
89 | | - WorkflowJob job = r.createProject(WorkflowJob.class, "p"); |
90 | | - job.setDefinition(new CpsFlowDefinition("def r = passthrough {}; echo r", true)); |
91 | | - |
92 | | - WorkflowRun build = r.buildAndAssertSuccess(job); |
93 | | - r.assertLogContains("hooray", build); |
94 | | - assertThat(ClosureCounter.get().closureCount, equalTo(0)); |
95 | | - assertThat(logger.getMessages(), not(hasItem(containsString("Stale closure")))); |
96 | | - } |
97 | | - |
98 | 86 | public static class BadBlockStep extends Step { |
99 | 87 |
|
100 | 88 | @DataBoundConstructor |
@@ -127,6 +115,19 @@ public boolean takesImplicitBlockArgument() { |
127 | 115 | } |
128 | 116 | } |
129 | 117 |
|
| 118 | + @Issue("JENKINS-75067") |
| 119 | + @Test |
| 120 | + public void executionWithBodyRunningSyncNotLeakClosures() throws Exception { |
| 121 | + logger.record(CpsThreadGroup.class, Level.WARNING).capture(10); |
| 122 | + WorkflowJob job = r.createProject(WorkflowJob.class, "p"); |
| 123 | + job.setDefinition(new CpsFlowDefinition("def r = passthrough {}; echo r", true)); |
| 124 | + |
| 125 | + WorkflowRun build = r.buildAndAssertSuccess(job); |
| 126 | + r.assertLogContains("hooray", build); |
| 127 | + assertThat(ClosureCounter.get().closureCount, equalTo(0)); |
| 128 | + assertThat(logger.getMessages(), not(hasItem(containsString("Stale closure")))); |
| 129 | + } |
| 130 | + |
130 | 131 | public static class PassthroughStep extends Step { |
131 | 132 |
|
132 | 133 | @DataBoundConstructor |
@@ -181,4 +182,34 @@ static ClosureCounter get() { |
181 | 182 | return ExtensionList.lookupSingleton(ClosureCounter.class); |
182 | 183 | } |
183 | 184 | } |
| 185 | + |
| 186 | + @Test public void refersToCycle() throws Exception { |
| 187 | + logger.record(CpsStepContext.class, Level.ALL); |
| 188 | + var p = r.createProject(WorkflowJob.class, "p"); |
| 189 | + p.setDefinition(new CpsFlowDefinition("refersToCycle()", true)); |
| 190 | + r.assertLogNotContains("StackOverflowError", r.buildAndAssertStatus(Result.UNSTABLE, p)); |
| 191 | + } |
| 192 | + public static final class RefersToCycleStep extends Step { |
| 193 | + @DataBoundConstructor public RefersToCycleStep() {} |
| 194 | + @Override public StepExecution start(StepContext context) throws Exception { |
| 195 | + return StepExecutions.synchronousNonBlockingVoid(context, ctx -> { |
| 196 | + var t1 = new IllegalStateException("extra"); |
| 197 | + var t2 = new FlowInterruptedException(Result.UNSTABLE, false); |
| 198 | + var t3 = new IllegalArgumentException("whatever"); |
| 199 | + t1.addSuppressed(t3); |
| 200 | + t3.addSuppressed(t1); |
| 201 | + ctx.onFailure(t2); |
| 202 | + ctx.onFailure(t1); |
| 203 | + }); |
| 204 | + } |
| 205 | + @TestExtension("refersToCycle") public static final class DescriptorImpl extends StepDescriptor { |
| 206 | + @Override public String getFunctionName() { |
| 207 | + return "refersToCycle"; |
| 208 | + } |
| 209 | + @Override public Set<? extends Class<?>> getRequiredContext() { |
| 210 | + return Set.of(); |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + |
184 | 215 | } |
0 commit comments