Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-20272] Don't monitor response on offline agents (#2911)
* [FIXED JENKINS-20272] Don't monitor response on offline agents * Updating to only not check if channel is null. * Fix broken test.
- Loading branch information
1 parent
564ca0b
commit 5f125d1
Showing
2 changed files
with
51 additions
and
1 deletion.
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
48 changes: 48 additions & 0 deletions
48
test/src/test/java/hudson/node_monitors/ResponseTimeMonitorTest.java
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package hudson.node_monitors; | ||
|
||
import hudson.model.User; | ||
import hudson.slaves.DumbSlave; | ||
import hudson.slaves.OfflineCause; | ||
import hudson.slaves.SlaveComputer; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
/** | ||
* @author Andrew Bayer | ||
*/ | ||
public class ResponseTimeMonitorTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
/** | ||
* Makes sure that it doesn't try to monitor an already-offline agent. | ||
*/ | ||
@Test | ||
@Issue("JENKINS-20272") | ||
public void skipOfflineAgent() throws Exception { | ||
DumbSlave s = j.createSlave(); | ||
SlaveComputer c = s.getComputer(); | ||
c.connect(false).get(); // wait until it's connected | ||
|
||
// Try as temporarily offline first. | ||
c.setTemporarilyOffline(true, new OfflineCause.UserCause(User.getUnknown(), "Temporarily offline")); | ||
assertNotNull(ResponseTimeMonitor.DESCRIPTOR.monitor(c)); | ||
|
||
// Now try as actually disconnected. | ||
c.setTemporarilyOffline(false, null); | ||
j.disconnectSlave(s); | ||
assertNull(ResponseTimeMonitor.DESCRIPTOR.monitor(c)); | ||
|
||
// Now reconnect and make sure we get a non-null response. | ||
c.connect(false).get(); // wait until it's connected | ||
|
||
assertNotNull(ResponseTimeMonitor.DESCRIPTOR.monitor(c)); | ||
} | ||
|
||
} |