-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear CpsBodyExecution.thread
#925
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,15 @@ | |
import groovy.lang.Closure; | ||
import hudson.model.Result; | ||
import hudson.slaves.DumbSlave; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import org.codehaus.groovy.runtime.ScriptBytecodeAdapter; | ||
import org.jenkinsci.plugins.workflow.actions.ErrorAction; | ||
import org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode; | ||
|
@@ -31,22 +34,23 @@ | |
import org.junit.Test; | ||
import org.jvnet.hudson.test.BuildWatcher; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.RestartableJenkinsRule; | ||
import org.jvnet.hudson.test.TestExtension; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.iterableWithSize; | ||
import static org.hamcrest.Matchers.not; | ||
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner; | ||
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import org.jvnet.hudson.test.JenkinsSessionRule; | ||
|
||
public class CpsBodyExecutionTest { | ||
|
||
@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher(); | ||
@Rule public RestartableJenkinsRule rr = new RestartableJenkinsRule(); | ||
@Rule public JenkinsSessionRule rr = new JenkinsSessionRule(); | ||
|
||
/** | ||
* When the body of a step is synchronous and explodes, the failure should be recorded and the pipeline job | ||
|
@@ -60,7 +64,7 @@ public class CpsBodyExecutionTest { | |
* never arrives. | ||
*/ | ||
@Test | ||
public void synchronousExceptionInBody() throws Exception { | ||
public void synchronousExceptionInBody() throws Throwable { | ||
rr.then(jenkins -> { | ||
WorkflowJob p = jenkins.createProject(WorkflowJob.class); | ||
p.setDefinition(new CpsFlowDefinition("synchronousExceptionInBody()",true)); | ||
|
@@ -138,7 +142,7 @@ public boolean start() throws Exception { | |
} | ||
|
||
@Issue("JENKINS-34637") | ||
@Test public void currentExecutions() throws Exception { | ||
@Test public void currentExecutions() throws Throwable { | ||
rr.then(jenkins -> { | ||
WorkflowJob p = jenkins.createProject(WorkflowJob.class); | ||
p.setDefinition(new CpsFlowDefinition("parallel main: {retainsBody {parallel a: {retainsBody {semaphore 'a'}}, b: {retainsBody {semaphore 'b'}}}}, aside: {semaphore 'c'}", true)); | ||
|
@@ -200,7 +204,7 @@ public static class Execution extends AbstractStepExecutionImpl { | |
} | ||
|
||
@Issue({"JENKINS-53709", "JENKINS-41791"}) | ||
@Test public void popContextVarsOnBodyCompletion() { | ||
@Test public void popContextVarsOnBodyCompletion() throws Throwable { | ||
rr.then(r -> { | ||
DumbSlave s = r.createOnlineSlave(); | ||
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); | ||
|
@@ -226,7 +230,7 @@ public static class Execution extends AbstractStepExecutionImpl { | |
} | ||
|
||
@Issue("JENKINS-63164") | ||
@Test public void closureCapturesCpsBodyExecution() { | ||
@Test public void closureCapturesCpsBodyExecution() throws Throwable { | ||
rr.then(r -> { | ||
DumbSlave s = r.createOnlineSlave(); | ||
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); | ||
|
@@ -253,4 +257,28 @@ public static class Execution extends AbstractStepExecutionImpl { | |
}); | ||
} | ||
|
||
@Test public void capturedBodies() throws Throwable { | ||
var semaphores = List.of("y1", "y2"); | ||
AtomicReference<Path> buildXml = new AtomicReference<>(); | ||
rr.then(r -> { | ||
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); | ||
p.setDefinition(new CpsFlowDefinition("parallel x1: {}, x2: {g = {x -> x + 1}; echo(/${g(1)}/)}; parallel y1: {semaphore 'y1'}, y2: {semaphore 'y2'}", true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (note lack of |
||
WorkflowRun b = p.scheduleBuild2(0).waitForStart(); | ||
for (var semaphore : semaphores) { | ||
SemaphoreStep.waitForStart(semaphore + "/1", b); | ||
} | ||
buildXml.set(b.getRootDir().toPath().resolve("build.xml")); | ||
}); | ||
Files.copy(buildXml.get(), System.out); | ||
rr.then(r -> { | ||
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class); | ||
WorkflowRun b = p.getLastBuild(); | ||
for (var semaphore : semaphores) { | ||
SemaphoreStep.success(semaphore + "/1", null); | ||
} | ||
r.assertBuildStatusSuccess(r.waitForCompletion(b)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without fix:
|
||
new DepthFirstScanner().allNodes(b.getExecution()).stream().sorted(Comparator.comparing(n -> Integer.valueOf(n.getId()))).forEach(n -> System.out.println(n.getId() + " " + n.getDisplayName())); | ||
}); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The originally observed error, which I was unable to reproduce exactly in a functional test, involved the
CpsBodyExecution
being held fromParallelStepExecution.bodies
:In this case the
ParallelStepExecution
was complete, so there was no reason for it to still be holding onto itsbodies
. (There was no good reason forprogram.dat
to be holding onto theParallelStepExecution
itself; this was due to a forgottendef
.)