Skip to content

Only reconnect offline agent if it is not idle#2020

Open
gbhat618 wants to merge 5 commits into
jenkinsci:masterfrom
gbhat618:offline-agent-running-vm-termination-on-idle
Open

Only reconnect offline agent if it is not idle#2020
gbhat618 wants to merge 5 commits into
jenkinsci:masterfrom
gbhat618:offline-agent-running-vm-termination-on-idle

Conversation

@gbhat618

@gbhat618 gbhat618 commented Jul 10, 2026

Copy link
Copy Markdown

Fixes #1752, checked the reconnection logic introduced in #1142 that it was intended for reconnecting busy agent that faced intermittent network failure.

Re-ordered the conditional logic to do the local check before making AWS API call in computer.getState().

Previously such agents would never hit the idle termination because the Computer#connect would bump its connect time, thus never allowing to expire the idle timeout (described in #1752 (comment))

I believe it will also address the agents not being deleted during ssh key failure #1990 (comment). Note: this PR doesn't address the ssh key failure, but just that agent deletion would now start to happen when that issue is faced.

Testing

Automated Testing

Added a new unit test that using the existing machinery.

Manual Testing

  • Idle agent gets deleted

    • kept the Maximum Total Uses to the default -1 so the agent is not deleted after build is done.

    • configured Idle termination time to 3

    • triggered simple build node('ec2') { sh 'date' }

    • marked the agent offline manually

    • after 3 minutes agent is deleted.

      logs
        2026-07-10 07:51:33.792+0000 [id=213]   FINE    h.p.ec2.EC2RetentionStrategy#taskAccepted: maxTotalUses set to unlimited (-1) for agent i-008505dcc737b4cec
        2026-07-10 07:51:48.908+0000 [id=88]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
        2026-07-10 07:52:48.909+0000 [id=89]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
        2026-07-10 07:52:49.319+0000 [id=250]   FINE    h.p.ec2.EC2RetentionStrategy#internalCheck: Computer i-008505dcc737b4cec offline but not connecting, will check if it should be terminated because of the idle time configured
        2026-07-10 07:53:44.171+0000 [id=254]   FINE    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started EC2 alive agents monitor
        2026-07-10 07:53:45.055+0000 [id=254]   FINE    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished EC2 alive agents monitor. 879 ms
        2026-07-10 07:53:48.803+0000 [id=250]   FINE    h.p.ec2.EC2RetentionStrategy#internalCheck: Computer i-008505dcc737b4cec offline but not connecting, will check if it should be terminated because of the idle time configured
        2026-07-10 07:53:48.913+0000 [id=90]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
        2026-07-10 07:54:48.912+0000 [id=98]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
        2026-07-10 07:54:49.351+0000 [id=250]   FINE    h.p.ec2.EC2RetentionStrategy#internalCheck: Computer i-008505dcc737b4cec offline but not connecting, will check if it should be terminated because of the idle time configured
        2026-07-10 07:55:48.913+0000 [id=97]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
        2026-07-10 07:55:49.374+0000 [id=250]   FINE    h.p.ec2.EC2RetentionStrategy#internalCheck: Computer i-008505dcc737b4cec offline but not connecting, will check if it should be terminated because of the idle time configured
        2026-07-10 07:55:49.375+0000 [id=250]   INFO    h.p.ec2.EC2RetentionStrategy#internalCheck: Idle timeout of EC2 (ec2) - ec2-agent (i-008505dcc737b4cec) after 3 idle minutes, instance statusRUNNING
        2026-07-10 07:55:49.375+0000 [id=250]   INFO    h.p.ec2.EC2RetentionStrategy#internalCheck: Idle timeout of EC2 (ec2) - ec2-agent (i-008505dcc737b4cec) after 3 idle minutes, instance statusRUNNING
        2026-07-10 07:55:49.377+0000 [id=250]   INFO    h.plugins.ec2.EC2AbstractSlave#idleTimeout: EC2 instance idle time expired: i-008505dcc737b4cec
        2026-07-10 07:55:49.377+0000 [id=250]   INFO    h.plugins.ec2.EC2AbstractSlave#idleTimeout: EC2 instance idle time expired: i-008505dcc737b4cec
        2026-07-10 07:55:50.262+0000 [id=259]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Terminated EC2 instance (terminated): i-008505dcc737b4cec
        2026-07-10 07:55:50.262+0000 [id=259]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Terminated EC2 instance (terminated): i-008505dcc737b4cec
        2026-07-10 07:55:50.274+0000 [id=259]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Removed EC2 instance from jenkins controller: i-008505dcc737b4cec
        2026-07-10 07:55:50.274+0000 [id=259]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Removed EC2 instance from jenkins controller: i-008505dcc737b4cec
        2026-07-10 07:55:50.485+0000 [id=231]   INFO    h.r.SynchronousCommandTransport$ReaderThread#run: I/O error in channel EC2 (ec2) - ec2-agent (i-008505dcc737b4cec)
        java.io.EOFException
                at java.base/java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2933)
                at java.base/java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3428)
                at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:985)
                at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:416)
                at hudson.remoting.ObjectInputStreamEx.<init>(ObjectInputStreamEx.java:50)
                at hudson.remoting.Command.readFrom(Command.java:141)
                at hudson.remoting.Command.readFrom(Command.java:127)
                at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
                at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:62)
        Caused: java.io.IOException: Unexpected termination of the channel
                at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:80)                
      
      
  • Busy agent facing intermittent network issue is reconnected (behaves as before)

    • same setup was above, but changed the pipeline to node('ec2') { sh 'sleep 240' }

    • while the build was in progress, went to the ssh console of the VM (amazon linux), and restarted the ssh service with a 1 minute delay.

      sudo dnf install iptables -y
      sudo nohup bash -c 'iptables -I INPUT -p tcp --dport 22 -j DROP; sleep 120; iptables -D INPUT -p tcp --dport 22 -j DROP' > /dev/null 2>&1 &
      
    • jenkins showed connection drop logs,

      logs
      2026-07-10 08:16:48.904+0000 [id=99]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
       2026-07-10 08:17:03.616+0000 [id=314]   WARNING o.a.s.c.u.logging.LoggingUtils#warn: exceptionCaught(ClientSessionImpl[ec2-user@/98.92.160.168:22])[state=Opened] IOException: Operation timed out
       2026-07-10 08:17:03.619+0000 [id=317]   INFO    h.r.SynchronousCommandTransport$ReaderThread#run: I/O error in channel EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6)
       java.io.EOFException
               at java.base/java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2933)
               at java.base/java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3428)
               at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:985)
               at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:416)
               at hudson.remoting.ObjectInputStreamEx.<init>(ObjectInputStreamEx.java:50)
               at hudson.remoting.Command.readFrom(Command.java:141)
               at hudson.remoting.Command.readFrom(Command.java:127)
               at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
               at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:62)
       Caused: java.io.IOException: Unexpected termination of the channel
               at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:80)
       2026-07-10 08:17:48.907+0000 [id=89]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
       2026-07-10 08:17:49.453+0000 [id=415]   WARNING h.p.ec2.EC2RetentionStrategy#attemptReconnectIfOffline: EC2Computer EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6) is offline
       2026-07-10 08:17:49.453+0000 [id=415]   WARNING h.p.ec2.EC2RetentionStrategy#attemptReconnectIfOffline: EC2Computer EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6) is offline
       2026-07-10 08:17:49.454+0000 [id=415]   WARNING h.p.ec2.EC2RetentionStrategy#attemptReconnectIfOffline: Attempting to reconnect EC2Computer EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6)
       2026-07-10 08:17:49.454+0000 [id=415]   WARNING h.p.ec2.EC2RetentionStrategy#attemptReconnectIfOffline: Attempting to reconnect EC2Computer EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6)
       2026-07-10 08:17:49.455+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Launching instance: i-085c66e880d34e8a6
       2026-07-10 08:17:49.455+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Launching instance: i-085c66e880d34e8a6
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: bootstrap()
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: bootstrap()
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Getting keypair...
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Getting keypair...
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Using private key gbhat (SHA-1 fingerprint 6e:7c:32:94:5f:c8:f1:92:b4:b0:68:d1:ef:ef:35:1c:0c:a6:e0:82)
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Using private key gbhat (SHA-1 fingerprint 6e:7c:32:94:5f:c8:f1:92:b4:b0:68:d1:ef:ef:35:1c:0c:a6:e0:82)
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Authenticating as ec2-user
       2026-07-10 08:17:49.456+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Authenticating as ec2-user
       2026-07-10 08:17:49.755+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Connecting to 98.92.160.168 on port 22, with timeout 10000.
       2026-07-10 08:17:49.755+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Connecting to 98.92.160.168 on port 22, with timeout 10000.
       2026-07-10 08:17:49.978+0000 [id=314]   FINE    h.p.e.u.SSHClientManager$ClientHolder$1#sessionNegotiationOptionsCreated: Reordered host key algorithms for session: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp256,sk-ecdsa-sha2-nistp256@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-512,rsa-sha2-256,ssh-rsa
       2026-07-10 08:17:49.979+0000 [id=416]   INFO    hudson.plugins.ec2.EC2Cloud#log: Connected via SSH.
      
    • Build succeeded

      build log
      Started by user unknown or anonymous
      [Pipeline] Start of Pipeline
      [Pipeline] node
      Still waiting to schedule task
      ‘Jenkins’ doesn’t have label ‘ec2’
      Running on EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6) in /home/ec2-user/workspace/p
      [Pipeline] {
      [Pipeline] sh
      + sleep 240
      Cannot contact EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6): java.lang.InterruptedException
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      
    • This online agent becomes idle and gets deleted as expected too. (same behavior as before)

      logs
       2026-07-10 08:20:48.907+0000 [id=97]    FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
       ^[[B2026-07-10 08:21:48.907+0000 [id=90]        FINER   h.p.e.EC2Cloud$EC2ConnectionUpdater#doRun: Checking EC2 Connection on: ec2
       2026-07-10 08:21:49.397+0000 [id=415]   INFO    h.p.ec2.EC2RetentionStrategy#internalCheck: Idle timeout of EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6) after 3 idle minutes, instance statusRUNNING
       2026-07-10 08:21:49.397+0000 [id=415]   INFO    h.p.ec2.EC2RetentionStrategy#internalCheck: Idle timeout of EC2 (ec2) - ec2-agent (i-085c66e880d34e8a6) after 3 idle minutes, instance statusRUNNING
       2026-07-10 08:21:49.397+0000 [id=415]   INFO    h.plugins.ec2.EC2AbstractSlave#idleTimeout: EC2 instance idle time expired: i-085c66e880d34e8a6
       2026-07-10 08:21:49.397+0000 [id=415]   INFO    h.plugins.ec2.EC2AbstractSlave#idleTimeout: EC2 instance idle time expired: i-085c66e880d34e8a6
       2026-07-10 08:21:50.318+0000 [id=451]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Terminated EC2 instance (terminated): i-085c66e880d34e8a6
       2026-07-10 08:21:50.318+0000 [id=451]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Terminated EC2 instance (terminated): i-085c66e880d34e8a6
       2026-07-10 08:21:50.330+0000 [id=451]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Removed EC2 instance from jenkins controller: i-085c66e880d34e8a6
       2026-07-10 08:21:50.330+0000 [id=451]   INFO    h.plugins.ec2.EC2OndemandSlave#lambda$terminate$0: Removed EC2 instance from jenkins controller: i-085c66e880d34e8a6
      

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Comment on lines +705 to +709
// The idle timeout still expires and the instance is idle-terminated.
assertThat(
"The mock sets `idleTimeoutCalled` to true, if EC2AbstractSlave#idleTimeout is called",
idleTimeoutCalled.get(),
is(true));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is the best we can do atm with the existing test setup - though it doesn't prove that an agent is created inside Jenkins and deleted,
but uses mock computers that are anonymous inner classes in this test class. This assertion works because the mock here sets field idleTimeoutCalled for calling EC2AbstractSlave#idleTimeout

@Override
void idleTimeout() {
idleTimeoutCalled.set(true);
}

@gbhat618 gbhat618 Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note: this assertion won't fail even without the patch, because computer#connect doesn't work in this mock setup.

However the log assertion immediately below this demonstrates the failure the reconnect attempt, and fails the assertion.

Comment thread src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Outdated
&& (InstanceState.STOPPED.equals(state) || InstanceState.STOPPING.equals(state))) {
if (computer.isOnline()) {
LOGGER.info("External Stop of " + computer.getName() + " detected - disconnecting. instance status"
LOGGER.info("External Stop of " + computer.getName() + " detected - disconnecting. instance status "

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

(fix missing ws)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts EC2 agent retention behavior so that an agent marked offline is only automatically reconnected if it is not idle, allowing idle-termination to proceed for offline/idle agents (addressing #1752 / JENKINS-61789). It also reorders the reconnect condition to avoid unnecessary AWS API calls when local conditions already rule out reconnection.

Changes:

  • Update EC2RetentionStrategy#attemptReconnectIfOffline to skip reconnects for offline idle agents and to evaluate local state before calling computer.getState().
  • Add a unit test ensuring offline/idle agents still trigger idle-timeout termination and do not log reconnect attempts.
  • Minor log message formatting tweak.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java Changes reconnect gating to avoid reconnecting offline/idle agents and reduces unnecessary EC2 state lookups.
src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Adds regression test coverage for offline/idle termination behavior tied to issue #1752.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 318 to 322
private void attemptReconnectIfOffline(EC2Computer computer) {
try {
if (computer.getState() == InstanceState.RUNNING && computer.isOffline()) {
if (computer.isOffline() && !computer.isIdle() && computer.getState() == InstanceState.RUNNING) {
LOGGER.warning("EC2Computer " + computer.getName() + " is offline");
if (!computer.isConnecting()) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Without the patch the new test submitted fails,

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 3.460 s <<< FAILURE! -- in hudson.plugins.ec2.EC2RetentionStrategyTest
[ERROR] hudson.plugins.ec2.EC2RetentionStrategyTest.testDoNotReconnectOfflineIdleComputer -- Time elapsed: 3.443 s <<< FAILURE!
java.lang.AssertionError: 
No reconnection logs
Expected: <true>
     but: was <false>
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
        at hudson.plugins.ec2.EC2RetentionStrategyTest.testDoNotReconnectOfflineIdleComputer(EC2RetentionStrategyTest.java:712)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   EC2RetentionStrategyTest.testDoNotReconnectOfflineIdleComputer:712 No reconnection logs
Expected: <true>                                                                                                                                                                                                                                         
     but: was <false>                                                                                                                                                                                                                                    
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

(it attempted reconnect)

Comment thread src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Outdated
Comment thread src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Outdated

@jglick jglick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds reasonable. I did not take the time to study the test.

private void attemptReconnectIfOffline(EC2Computer computer) {
try {
if (computer.getState() == InstanceState.RUNNING && computer.isOffline()) {
if (computer.isOffline() && !computer.isIdle() && computer.getState() == InstanceState.RUNNING) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason to order the checks like this (avoiding work in short-circuit evaluation), or would the smaller diff

Suggested change
if (computer.isOffline() && !computer.isIdle() && computer.getState() == InstanceState.RUNNING) {
if (computer.getState() == InstanceState.RUNNING && computer.isOffline() && !computer.isIdle()) {

work just as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, it was to avoid the work in short-circuit. I had noticed in a thread dump the getState makes a network call; not exactly in this place but same file another method -

state = computer.getState(); // Get State before Uptime because getState will refresh the cached EC2

...
	at software.amazon.awssdk.core.client.handler.SdkSyncClientHandler.execute(SdkSyncClientHandler.java:45)
	at software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler.execute(AwsSyncClientHandler.java:53)
	at software.amazon.awssdk.services.ec2.DefaultEc2Client.describeInstances(DefaultEc2Client.java:21130)
	at hudson.plugins.ec2.CloudHelper.getInstance(CloudHelper.java:58)
	at hudson.plugins.ec2.CloudHelper.getInstanceWithRetry(CloudHelper.java:31)
	at hudson.plugins.ec2.EC2Computer.describeInstance(EC2Computer.java:194)
	at hudson.plugins.ec2.EC2Computer.getState(EC2Computer.java:215)
	at hudson.plugins.ec2.EC2RetentionStrategy.internalCheck(EC2RetentionStrategy.java:181)
	at hudson.plugins.ec2.EC2RetentionStrategy.runHeavyCheck(EC2RetentionStrategy.java:145)
	at hudson.plugins.ec2.EC2RetentionStrategy.lambda$check$1(EC2RetentionStrategy.java:128)
	at hudson.plugins.ec2.EC2RetentionStrategy$$Lambda/0x000000f001899ca0.run(Unknown Source)

Comment thread src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Outdated
Comment thread src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Outdated
Comment thread src/test/java/hudson/plugins/ec2/EC2RetentionStrategyTest.java Outdated
Comment on lines +714 to +715
logging.getMessages().stream().noneMatch(m -> m.contains("Attempting to reconnect")),
equalTo(true));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is probably a better matcher for this that would report the messages if the assertion failed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

right, fixed now.
now shows all the log entries,

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 2.976 s <<< FAILURE! -- in hudson.plugins.ec2.EC2RetentionStrategyTest
[ERROR] hudson.plugins.ec2.EC2RetentionStrategyTest.testDoNotReconnectOfflineIdleComputer -- Time elapsed: 2.960 s <<< FAILURE!
java.lang.AssertionError:
No reconnection logs
Expected: not a collection containing a string containing "Attempting to reconnect"
     but: was <[EC2Computer name is offline, Attempting to reconnect EC2Computer name, Computer id offline but not connecting, will check if it should be terminated because of the idle time configured, Idle timeout of name after 5 idle minutes, instance statusRUNNING]>
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
        at hudson.plugins.ec2.EC2RetentionStrategyTest.testDoNotReconnectOfflineIdleComputer(EC2RetentionStrategyTest.java:713)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   EC2RetentionStrategyTest.testDoNotReconnectOfflineIdleComputer:713 No reconnection logs
Expected: not a collection containing a string containing "Attempting to reconnect"
     but: was <[EC2Computer name is offline, Attempting to reconnect EC2Computer name, Computer id offline but not connecting, will check if it should be terminated because of the idle time configured, Idle timeout of name after 5 idle minutes, instance statusRUNNING]>
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-61789] Agent nodes marked as 'offline' are not terminated when they have been idle beyond the idle termination time setting

3 participants