-
Notifications
You must be signed in to change notification settings - Fork 129
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
[JENKINS-54078] JEP-210 compatibility #74
[JENKINS-54078] JEP-210 compatibility #74
Conversation
@@ -28,7 +28,7 @@ | |||
<parent> | |||
<groupId>org.jenkins-ci.plugins</groupId> | |||
<artifactId>plugin</artifactId> | |||
<version>3.19</version> | |||
<version>3.25</version> |
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.
Various changes to pick up JEP-210 binaries.
pom.xml
Outdated
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-durable-task-step</artifactId> | ||
<version>2.3</version> | ||
<version>2.22-rc713.c51e25cf0eef</version> <!-- TODO https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/75 --> |
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.
jenkinsci/workflow-durable-task-step-plugin#75, to get ABORTED
rather than FAILURE
in the test.
Note that this build is actually older than the 2.22 on the update center, but it does contain jenkinsci/workflow-durable-task-step-plugin#63 and the subsequent commits are uninteresting.
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.
Released as workflow-durable-task-step 2.24.
p.setDefinition(new CpsFlowDefinition("" + | ||
"node('!master') {\n" + | ||
" timeout(time:5, unit:'SECONDS', activity: true) {\n" + | ||
" sh 'set +x; echo NotHere; sleep 3; echo NotHereYet; sleep 3; echo JustHere; sleep 10; echo ShouldNot'\n" + |
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.
Cannot use echo
steps as in the other tests, because we need to demonstrate serialization of the ConsoleLogFilter
impl, which only happens if a nested step actually remotes its TaskListener
.
Looks like the test failure is because workflow-basic-steps-plugin/src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepTest.java Line 103 in 8d0a946
|
pom.xml
Outdated
<workflow-cps-plugin.version>2.32</workflow-cps-plugin.version> | ||
<workflow-support-plugin.version>2.14</workflow-support-plugin.version> | ||
<workflow-api-plugin.version>2.28</workflow-api-plugin.version> | ||
<workflow-cps-plugin.version>2.58-beta-1</workflow-cps-plugin.version> |
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.
These can be updated to non-beta versions now.
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.
Remind me to do so once jenkinsci/workflow-durable-task-step-plugin#75 is in a release.
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.
Ok, if that PR isn't released by next Friday I will release it and ping you then.
I will use this PR to investigate JENKINS-54078. |
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.
Looks fine to me, although it would be nice to understand the root cause.
pom.xml
Outdated
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-durable-task-step</artifactId> | ||
<version>2.3</version> | ||
<version>2.22-rc713.c51e25cf0eef</version> <!-- TODO https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/75 --> |
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.
Released as workflow-durable-task-step 2.24.
src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java
Show resolved
Hide resolved
} | ||
|
||
private Object writeReplace() { | ||
Channel ch = Channel.current(); | ||
return ch == null ? this : new ConsoleLogFilterImpl(ch.export(ResetCallback.class, callback)); |
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.
Maybe the issue is that only the marshaller holds the reference to the exported object, so after the object is completely serialized it is free to be garbage collected?
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.
AFAICT the issue was that this code released all exported objects when a Callable
finished, insofar as those objects had originally been exported within the dynamic scope of that Callable
’s serialization. Or something like this. I could not follow exactly what the logic was, and the documentation was scant. At any rate, the revised strategy with the SlaveToMasterCallable
is simpler to reason about explicitly.
I intend to amend 0918918 to be more secure. Also the CI seems to be broken and I would like to get a clean build. |
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-durable-task-step</artifactId> | ||
<version>2.3</version> | ||
<version>2.24</version> |
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.
FTR this was to pick up the fix of JENKINS-28822.
src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java
Show resolved
Hide resolved
Having difficulty coming up with a convincing test case for the upgrade scenario. Was playing with something like @Issue("JENKINS-54078")
@LocalData
@Test public void activityUpgrade() {
story.then(r -> {
r.createSlave();
/* Setup, with workflow-job reverted to 2.25 and src/main/ from workflow-basic-steps 2.11:
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node('!master') {\n" +
" timeout(time: 5, unit: 'SECONDS', activity: true) {\n" +
" remotePrint 'NotHere'\n" +
" sleep 3\n" +
" remotePrint 'NotHereYet'\n" +
" sleep 3\n" +
" remotePrint 'JustHere'\n" +
" while (true) {\n" +
" sleep 10\n" +
" remotePrint 'ShouldNot'\n" +
" }\n" +
" }\n" +
"}\n", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
r.waitForMessage("“JustHere” from agent", b);
r.waitForMessage("Sleeping for 10 sec", b);
Runtime.getRuntime().halt(1);
*/
WorkflowRun b = r.jenkins.getItemByFullName("p", WorkflowJob.class).getBuildByNumber(1);
r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
r.assertLogContains("Cancelling nested steps due to timeout", b);
/* Actually we get this, once, because the sleep expired:
r.assertLogNotContains("ShouldNot", b);
*/
b.getLogText().writeRawLogTo(0, System.out);
});
}
// TODO adapted from workflow-job; consider pushing into tests JAR of workflow-support for reuse
public static final class RemotePrintStep extends Step {
public final String message;
@DataBoundConstructor public RemotePrintStep(String message) {
this.message = message;
}
@Override public StepExecution start(StepContext context) throws Exception {
return new Execution(context, message);
}
private static final class Execution extends SynchronousNonBlockingStepExecution<Void> {
private final String message;
Execution(StepContext context, String message) {
super(context);
this.message = message;
}
@Override protected Void run() throws Exception {
return getContext().get(Node.class).getChannel().call(new PrintCallable(getContext().get(TaskListener.class), message));
}
}
private static final class PrintCallable extends MasterToSlaveCallable<Void, RuntimeException> {
private final TaskListener listener;
private final String message;
PrintCallable(TaskListener listener, String message) {
this.listener = listener;
this.message = message;
}
@Override public Void call() throws RuntimeException {
listener.getLogger().println("“" + message + "” from " + (JenkinsJVM.isJenkinsJVM() ? "master" : "agent"));
return null;
}
}
@TestExtension public static final class DescriptorImpl extends StepDescriptor {
@Override public Set<? extends Class<?>> getRequiredContext() {
return ImmutableSet.of(Node.class, TaskListener.class);
}
@Override public String getFunctionName() {
return "remotePrint";
}
}
} However even before the upgrade it does not work unless I also diff --git a/src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java b/src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java
index 20f2f21..76c0154 100644
--- a/src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java
+++ b/src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java
@@ -75,7 +75,11 @@ public class TimeoutStepExecution extends AbstractStepExecutionImpl {
@Override
public void onResume() {
- setupTimer(System.currentTimeMillis(), false);
+ if (activity) {
+ resetTimer();
+ } else {
+ setupTimer(System.currentTimeMillis(), false);
+ }
}
private TaskListener listener() { because Related to that, there seems to be no existing coverage for the case that activity is seen after a restart and the build succeeds. Anyway, I think for now I am giving up on a test case for the upgrade, and will just write the probable fix based on reasoning. |
…t use it for new builds.
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 fix looks good to me, and I did some manual testing across upgrades which worked as expected.
Demonstrates that abayer#1 was a necessary amendment to #62 in order to make
timeout
work properly with remote durable tasks as of JEP-210. If you disable that fix usingthen the build fails as expected:
Some more discussion: jenkinsci/workflow-support-plugin#15 (comment)
And then amends that change for JENKINS-54078 because it turns out (as I just happened to learn yesterday in jenkinsci/pipeline-cloudwatch-logs-plugin@f66f638!) that
Channel.export
is pretty much useless; for some reason I have yet to track down,FilePath
calls from the Git plugin (but not those from, say, thesh
step) trigger collection of references.