# Test Harness: create agent with multiple executors?

**URL:** <https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545>\
**Category:** Ask a question\
**Tags:** question, jenkins-test-harness\
**Created:** [April 8, 2025, 11:07am UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545 "2025-04-08T11:07:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [April 8, 2025, 11:07am UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/1 "2025-04-08T11:07:40Z")

</div>

I have this test that uses [`jenkins-test-harness`](https://github.com/jenkinsci/jenkins-test-harness/):

```java
class JenkinsUtilsTest extends spock.lang.Specification {

    @spock.lang.Shared
    @org.junit.ClassRule
    JenkinsRule harness = new JenkinsRule()

    void setupSpec() {
        hudson.model.Slave node = harness.createSlave('an-agent', null, null)
        node.numExecutors = 2
        harness.waitOnline(node)
    }

    void 'check parallel works'() {
        given:
        def job = harness.createProject(WorkflowJob)
        job.definition = new org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition('''
        parallel([
            sleeper: {
                node('an-agent') {
                    echo '--- going to sleep'
                    sleep time: 15, unit: 'SECONDS'
                    echo '--- done sleeping'
                }
            },
            waiter: {
                echo '--- pause in favor of sleeper'
                sleep time: 5, unit: 'SECONDS'
                node('an-agent') {
                    echo '--- done waiting'
                }
            }
        ])
        ''', true)

        when:
        WorkflowRun run = harness.buildAndAssertSuccess(job)

        then:
        harness.assertLogContains('show me the logs', run)
    }

```

When I run it, the logs say:

```
    [Pipeline] Start of Pipeline
    [Pipeline] parallel
    [Pipeline] { (Branch: sleeper)
    [Pipeline] { (Branch: waiter)
    [Pipeline] node
    [Pipeline] echo
    --- pause in favor of sleeper
    [Pipeline] sleep
    Sleeping for 5 sec
    Running on an-agent in /tmp/j h3074825386784972163/agent-work-dirs/an-agent/workspace/test0
    [Pipeline] {
    [Pipeline] echo
    --- going to sleep
    [Pipeline] sleep
    Sleeping for 15 sec
    [Pipeline] node
    [Pipeline] echo
    --- done sleeping
    [Pipeline] }
    Running on an-agent in /tmp/j h3074825386784972163/agent-work-dirs/an-agent/workspace/test0
    [Pipeline] // node
    [Pipeline] {
    [Pipeline] }
    [Pipeline] echo
    --- done waiting
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] }
    [Pipeline] // parallel
    [Pipeline] End of Pipeline

```

, so clearly there is only one Executor on the agent. I can confirm this asserting `node.computer.executors.size() == 2` in the setup - it is actually `1`, just like the [`hudson.model.Slave#getNumExecutors()` docs](https://javadoc.jenkins-ci.org/hudson/model/Slave.html#getNumExecutors()) state:

> This may be different from `getExecutors().size()` because it takes time to adjust the number of executors.

But how do I actually ensure that the number of executors has adjusted? Or better yet, force the adjustion - as I tried `Thread.sleep(60000)` and it did nothing.

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [April 22, 2025, 10:46pm UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/2 "2025-04-22T22:46:34Z")

</div>

you will need to do

```auto
node.toComputer().setNumExecutors(2)

```

---

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [April 23, 2025, 10:07am UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/3 "2025-04-23T10:07:35Z")

</div>

Thank you for chiming in @mawinter69 . There does not seem to be `setNumExecutors` in the [`hudson.slaves.SlaveComputer` object](https://javadoc.jenkins-ci.org/hudson/slaves/SlaveComputer.html) returned by `.toComputer()` or `.getComputer()` – only in [`hudson.model.Slave`](https://javadoc.jenkins-ci.org/hudson/model/Slave.html#setNumExecutors(int)) itself…

```auto
JenkinsUtilsTest > classMethod FAILED
    groovy.lang.MissingMethodException: No signature of method: hudson.slaves.SlaveComputer.setNumExecutors() is applicable for argument types: (java.lang.Integer) values: [2]
    Possible solutions: getNumExecutors(), getAllExecutors(), getExecutors()

```

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [April 23, 2025, 10:30am UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/4 "2025-04-23T10:30:19Z")

</div>

ah sorry `setNumExecutors` is private in `Computer` class

---

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [April 29, 2025, 12:02pm UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/5 "2025-04-29T12:02:37Z")

</div>

@mawinter69 do you maybe have some other ideas by any chance, or maybe know someone else we can try pinging here? 🙏

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [April 29, 2025, 12:54pm UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/6 "2025-04-29T12:54:08Z")

</div>

You can use the following trick

```auto
node.numExecutors = 2
harness.jenkins.getNodesObject().replaceNode(node, node);

```

---

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [May 1, 2025, 1:24pm UTC](https://community.jenkins.io/t/test-harness-create-agent-with-multiple-executors/29545/7 "2025-05-01T13:24:35Z")

</div>

Thank you very much Markus, that did it! Was afraid it would incur some additional waits for reinitialization to complete, but seems to go almost instantly. 🎉
