Skip to content

Commit 98fc851

Browse files
committed
Wait for builds to finish in new tests
1 parent bde0c1b commit 98fc851

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/test/java/org/jenkinsci/plugins/workflow/support/storage/BulkFlowNodeStorageTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.jenkinsci.plugins.workflow.support.storage;
2626

27+
import hudson.model.Result;
2728
import hudson.util.RobustReflectionConverter;
2829
import java.io.File;
2930
import java.util.ArrayList;
@@ -84,6 +85,9 @@ public final class BulkFlowNodeStorageTest {
8485
*/
8586
var p = r.jenkins.getItemByFullName("test0", WorkflowJob.class);
8687
var b = p.getLastBuild();
88+
// Build is unresumable because the local data was created with PERFORMANCE_OPTIMIZED without a clean shutdown.
89+
r.assertBuildStatus(Result.FAILURE, r.waitForCompletion(b));
90+
// Existing flow nodes should still be preserved though.
8791
var stageBodyStartNode = (StepStartNode) b.getExecution().getNode("4");
8892
assertThat(stageBodyStartNode, not(nullValue()));
8993
var label = stageBodyStartNode.getPersistentAction(LabelAction.class);

src/test/java/org/jenkinsci/plugins/workflow/support/storage/SimpleXStreamStorageTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jenkinsci.plugins.workflow.support.storage;
22

33

4+
import hudson.model.Result;
45
import hudson.util.RobustReflectionConverter;
56
import java.io.File;
67
import java.util.logging.Level;
@@ -10,6 +11,7 @@
1011
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode;
1112
import org.jenkinsci.plugins.workflow.graph.AtomNode;
1213
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
14+
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
1315
import org.junit.Assert;
1416
import org.junit.Rule;
1517
import org.junit.Test;
@@ -100,6 +102,8 @@ public void testDeferWriteAndFlush() throws Exception {
100102
*/
101103
var p = j.jenkins.getItemByFullName("test0", WorkflowJob.class);
102104
var b = p.getLastBuild();
105+
SemaphoreStep.success("wait/1", null);
106+
j.assertBuildStatus(Result.SUCCESS, j.waitForCompletion(b));
103107
var stageBodyStartNode = (StepStartNode) b.getExecution().getNode("4");
104108
assertThat(stageBodyStartNode, not(nullValue()));
105109
var label = stageBodyStartNode.getPersistentAction(LabelAction.class);

src/test/java/org/jenkinsci/plugins/workflow/test/steps/SemaphoreStep.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ public static class Execution extends AbstractStepExecutionImpl {
234234
}
235235
}
236236

237+
@Override public void onResume() {
238+
// Only matters for restarts across different JVMs, for example if using @LocalData.
239+
State s = State.get();
240+
String c = Jenkins.XSTREAM.toXML(getContext());
241+
synchronized (s) {
242+
if (s.returnValues.containsKey(k)) {
243+
getContext().onSuccess(s.returnValues.get(k));
244+
} else if (s.errors.containsKey(k)) {
245+
getContext().onFailure(s.errors.get(k));
246+
} else {
247+
s.contexts.put(k, c);
248+
}
249+
s.notifyAll();
250+
}
251+
}
252+
237253
private static final long serialVersionUID = 1L;
238254

239255
}

0 commit comments

Comments
 (0)