Skip to content

Commit

Permalink
Add test that demonstrates what happens when saving a FlowNode for a …
Browse files Browse the repository at this point in the history
…completed execution
  • Loading branch information
dwnusbaum committed Jan 4, 2024
1 parent a2426c0 commit 5507e1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ public void saveActions(FlowNode node, List<Action> actions) throws IOException
if (storage == null) {
throw new IOException("storage not yet loaded");
} else if (isComplete()) {
throw new IOException("Cannot save actions for " + node + " on completed execution " + this + ": " + actions);
throw new IOException("Cannot save actions for " + node + " for completed execution " + this + ": " + actions);
}
storage.saveActions(node, actions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -49,6 +50,7 @@
import hudson.model.Result;
import hudson.model.TaskListener;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -914,4 +916,15 @@ public boolean takesImplicitBlockArgument() {
});
}

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

}

0 comments on commit 5507e1a

Please sign in to comment.