Skip to content

Commit 5507e1a

Browse files
committed
Add test that demonstrates what happens when saving a FlowNode for a completed execution
1 parent a2426c0 commit 5507e1a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ public void saveActions(FlowNode node, List<Action> actions) throws IOException
12771277
if (storage == null) {
12781278
throw new IOException("storage not yet loaded");
12791279
} else if (isComplete()) {
1280-
throw new IOException("Cannot save actions for " + node + " on completed execution " + this + ": " + actions);
1280+
throw new IOException("Cannot save actions for " + node + " for completed execution " + this + ": " + actions);
12811281
}
12821282
storage.saveActions(node, actions);
12831283
}

plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecutionTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.junit.Assert.assertEquals;
3434
import static org.junit.Assert.assertFalse;
3535
import static org.junit.Assert.assertNotNull;
36+
import static org.junit.Assert.assertThrows;
3637
import static org.junit.Assert.assertTrue;
3738
import static org.junit.Assert.fail;
3839

@@ -49,6 +50,7 @@
4950
import hudson.model.Result;
5051
import hudson.model.TaskListener;
5152
import java.io.File;
53+
import java.io.IOException;
5254
import java.io.Serializable;
5355
import java.net.HttpURLConnection;
5456
import java.net.MalformedURLException;
@@ -914,4 +916,15 @@ public boolean takesImplicitBlockArgument() {
914916
});
915917
}
916918

919+
@Test public void flowNodesCantBeSavedAfterExecutionCompletes() throws Throwable {
920+
sessions.then(r -> {
921+
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
922+
p.setDefinition(new CpsFlowDefinition("echo 'Hello, world!'", true));
923+
WorkflowRun b = r.buildAndAssertSuccess(p);
924+
FlowNode echoStep = b.getExecution().getNode("3");
925+
IOException e = assertThrows(IOException.class, echoStep::save);
926+
assertThat(e.getMessage(), containsString("Cannot save actions for " + echoStep + " for completed execution " + b.getExecution()));
927+
});
928+
}
929+
917930
}

0 commit comments

Comments
 (0)