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

[FIXED JENKINS-20272] Don't monitor response on offline agents #2911

Merged
merged 3 commits into from Jul 30, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,7 +23,6 @@
*/
package hudson.node_monitors;

import hudson.Util;
import hudson.Extension;
import hudson.model.Computer;
import hudson.remoting.Callable;
Expand All @@ -49,6 +48,9 @@ public class ResponseTimeMonitor extends NodeMonitor {
public static final AbstractNodeMonitorDescriptor<Data> DESCRIPTOR = new AbstractAsyncNodeMonitorDescriptor<Data>() {
@Override
protected Callable<Data,IOException> createCallable(Computer c) {
if (c.getChannel() == null) {
return null;
}
return new Step1(get(c));
}

Expand Down
@@ -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);
c.disconnect(new OfflineCause.UserCause(User.getUnknown(), "Disconnecting"));
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));
}

}