Skip to content
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-26398] More flexible versions of createSlave #428

Merged
merged 4 commits into from
May 2, 2022

Conversation

jglick
Copy link
Member

@jglick jglick commented May 2, 2022

JENKINS-26398

Inspired by changes being made in jenkinsci/workflow-durable-task-step-plugin#180. Cleans up some tech debt from jenkinsci/pipeline-plugin#34 & jenkinsci/credentials-binding-plugin#3.

  • Fixes createSlave overloads to use a more stable agent workdir compatible with JenkinsSessionRule.
  • Introduces InboundAgentRule which is better suited to simulating agent disconnections.

src/main/java/org/jvnet/hudson/test/InboundAgentRule.java Outdated Show resolved Hide resolved
}
// TODO 2.216+ support WebSocket option
DumbSlave s = new DumbSlave(name, new File(r.jenkins.getRootDir(), "agent-work-dirs/" + name).getAbsolutePath(), new JNLPLauncher(true));
s.setNumExecutors(1); // TODO pending 2.234+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common use case I have seen in plugins is the desire to create an agent with more than one executor for complex testing scenarios, for example in throttle-concurrent-builds. While I recognize that this is not a use case you are intending to address in this PR, I think it would be worth thinking about how to accommodate such a use case in a future change and designing the API to support (or at least not preclude) such a future use case.

Copy link
Member Author

@jglick jglick May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing precludes you from calling setNumExecutors on the return value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if I recall correctly that might be too late, since we would have already launched the agent with the wrong number of executors, and setNumExecutors doesn't relaunch it. And it is awkward to launch with the wrong number and then relaunch with the correct number. So I think to accommodate such a future use case the API that launches the agent would need to support customizing the number of executors prior to launch. If the API you are proposing here can be extended to support that use case, great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this requirement is pretty rare, and in fact there are only a handful of known use cases where specifically inbound agent is required (regular createSlave handles other cases), I am not inclined to complicate the API with an unused parameter. If and when somebody needs something like that, they could propose an API addition for it, or simply write their own agent launch code as was done previously.

"-Xmx512m",
"-XX:+PrintCommandLineFlags",
"-Djava.awt.headless=true"));
if (JenkinsRule.SLAVE_DEBUG_PORT > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: untested; I am not even exactly sure how you arrange for this property to be set in the Surefire JVM. Adapted from

SLAVE_DEBUG_PORT>0 ? " -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address="+(SLAVE_DEBUG_PORT+sz): "",
but compare
if (new DisableOnDebug(null).isDebugging()) {
argv.add("-agentlib:jdwp=transport=dt_socket,server=y");
}
which is fully automatic.

@jglick jglick merged commit 2b3c5d1 into jenkinsci:master May 2, 2022
@jglick jglick deleted the agents-JENKINS-26398 branch May 2, 2022 17:52
jglick added a commit to jglick/credentials-binding-plugin that referenced this pull request May 2, 2022
jglick added a commit to jglick/workflow-durable-task-step-plugin that referenced this pull request May 2, 2022
jglick added a commit to jglick/workflow-basic-steps-plugin that referenced this pull request May 4, 2022
@basil
Copy link
Member

basil commented Jul 8, 2022

Causes org.jenkinsci.plugins.workflow.steps.scm.SCMStepTest#checkoutsRestored to start failing with

java.lang.AssertionError: 

Expected: a string containing "Cloning the remote Git repository"
     but: was "Started by an SCM change
[Pipeline] Start of Pipeline
[Pipeline] node
Running on slave0 in /home/jenkins/workspace/Tools_bom_PR-1255/pct-work/workflow-scm-step/target/tmp/j h17894114103649561928/agent-work-dirs/slave0/workspace/p
[Pipeline] {
[Pipeline] ws
Running in /home/jenkins/workspace/Tools_bom_PR-1255/pct-work/workflow-scm-step/target/tmp/j h17894114103649561928/agent-work-dirs/slave0/workspace/p@2
[Pipeline] {
[Pipeline] git
The recommended git tool is: NONE
No credentials specified
Fetching changes from the remote Git repository
Checking out Revision 01ae2e7fa78cc0696363f238c012a7aff4240801 (refs/remotes/origin/master)
 > git rev-parse --resolve-git-dir /home/jenkins/workspace/Tools_bom_PR-1255/pct-work/workflow-scm-step/target/tmp/j h17894114103649561928/agent-work-dirs/slave0/workspace/p@2/.git # timeout=10
 > git config remote.origin.url /tmp/junit13354845484223236222/junit3675871739211897507 # timeout=10
Fetching upstream changes from /tmp/junit13354845484223236222/junit3675871739211897507
 > git --version # timeout=10
 > git --version # 'git version 2.34.1'
 > git fetch --tags --force --progress -- /tmp/junit13354845484223236222/junit3675871739211897507 +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 01ae2e7fa78cc0696363f238c012a7aff4240801 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master 01ae2e7fa78cc0696363f238c012a7aff4240801 # timeout=10
Commit message: "next"
 > git rev-list --no-walk c41f60902fcb334dd411f0032c66e949505c05dc # timeout=10
[Pipeline] }
[Pipeline] // ws
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
"
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
	at org.jvnet.hudson.test.JenkinsRule.assertLogContains(JenkinsRule.java:1547)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStepTest.lambda$checkoutsRestored$2(SCMStepTest.java:125)
	at org.jvnet.hudson.test.RestartableJenkinsRule$3.evaluate(RestartableJenkinsRule.java:245)
	at org.jvnet.hudson.test.RestartableJenkinsRule$6.evaluate(RestartableJenkinsRule.java:293)
	at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:616)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.lang.Thread.run(Thread.java:833)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants