Skip to content
Permalink
Browse files

Merge pull request #224 from svanoort/fix-final-lazy-load-issue-JENKI…

…NS-50888

Fix and test for JENKINS-50888 by supporting serialization of execution before onLoad was called
  • Loading branch information
svanoort committed May 3, 2018
2 parents bdab2e1 + 8410c9f commit 54424895869f36d6c7377e167c5c1fa4ca959dc0
@@ -1610,11 +1610,25 @@ public void marshal(Object source, HierarchicalStreamWriter w, MarshallingContex
}
writeChild(w, context, "iota", e.iota.get(), Integer.class);
synchronized (e) {
for (FlowHead h : e.heads.values()) {
writeChild(w, context, "head", h.getId() + ":" + h.get().getId(), String.class);
if (e.headsSerial != null && (e.heads == null || e.heads.isEmpty())) { // Persisting before onLoad has called to load up the real heads
// Note: unlike start nodes, heads should not be empty once onLoad loading has happened
for (Entry<Integer, String> entry : e.headsSerial.entrySet()) {
writeChild(w, context, "head", entry.getKey() + ":" + entry.getValue(), String.class);
}
} else { // onLoad was invoked, we have real heads
for (FlowHead h : e.heads.values()) {
writeChild(w, context, "head", h.getId() + ":" + h.get().getId(), String.class);
}
}
for (BlockStartNode st : e.startNodes) {
writeChild(w, context, "start", st.getId(), String.class);

if (e.startNodesSerial != null && (e.startNodes == null)) { // Start nodes have not been lazy-loaded yet
for (String startId : e.startNodesSerial) {
writeChild(w, context, "start", startId, String.class);
}
} else { // Start nodes were loaded, so we can convert back to serial form
for (BlockStartNode st : e.startNodes) {
writeChild(w, context, "start", st.getId(), String.class);
}
}
writeChild(w, context, "done", e.done, Boolean.class);
}
@@ -20,6 +20,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RestartableJenkinsRule;

@@ -337,4 +338,25 @@ public void inProgressButStartBlocksLost() throws Exception {
assertCompletedCleanly(run);
});
}

@Issue("JENKINS-50888") // Tried to modify build without lazy load being triggered
@Test public void modifyBeforeLazyLoad() {
story.then(r -> { // Normal build
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'dosomething'", true));
r.buildAndAssertSuccess(p);
});
story.then(r -> { // But wait, we try to modify the build without loading the execution
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
b.setDescription("Bob");
b.save(); // Before the JENKINS-50888 fix this would trigger an IOException
});
story.then( r-> { // Verify that the FlowExecutionOwner can trigger lazy-load correctly
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
Assert.assertEquals("Bob", b.getDescription());
Assert.assertEquals("4", b.getExecution().getCurrentHeads().get(0).getId());
});
}
}

0 comments on commit 5442489

Please sign in to comment.
You can’t perform that action at this time.