Skip to content

Commit 9eb126d

Browse files
authored
Pointless delay in AgentConnectionBase.isSuccessfullyConnected (#457)
1 parent 22553bb commit 9eb126d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/test/java/hudson/plugins/sshslaves/agents/AgentConnectionBase.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.jvnet.hudson.test.JenkinsRule;
1313
import hudson.model.Descriptor;
1414
import hudson.model.Node;
15+
import hudson.model.Slave;
1516
import hudson.plugins.sshslaves.SSHLauncher;
1617
import hudson.plugins.sshslaves.rules.CheckIsDockerAvailable;
1718
import hudson.plugins.sshslaves.rules.CheckIsLinuxOrMac;
@@ -23,7 +24,6 @@
2324
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
2425
import com.cloudbees.plugins.credentials.domains.Domain;
2526
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
26-
import static org.junit.Assert.assertTrue;
2727

2828
/**
2929
* Base class to test connections to a remote SSH Agent
@@ -53,24 +53,25 @@ public class AgentConnectionBase {
5353
public Timeout globalTimeout= new Timeout(4, TimeUnit.MINUTES);
5454

5555
protected boolean isSuccessfullyConnected(Node node) throws IOException, InterruptedException {
56-
boolean ret = false;
5756
int count = 0;
5857
while (count < 30) {
5958
Thread.sleep(1000);
6059
String log = node.toComputer().getLog();
61-
ret = log.contains("Agent successfully connected and online");
62-
count++;
60+
if (log.contains("Agent successfully connected and online")) {
61+
return true;
62+
}
6363
}
64-
return ret;
64+
return false;
6565
}
6666

6767
protected void waitForAgentConnected(Node node) throws InterruptedException {
68-
int count = 0;
69-
while (!node.toComputer().isOnline() && count < 150) {
70-
Thread.sleep(1000);
71-
count++;
68+
try {
69+
j.waitOnline((Slave) node);
70+
} catch (InterruptedException | RuntimeException x) {
71+
throw x;
72+
} catch (Exception x) {
73+
throw new RuntimeException(x);
7274
}
73-
assertTrue(node.toComputer().isOnline());
7475
}
7576

7677
protected Node createPermanentAgent(String name, String host, int sshPort, String keyResourcePath, String passphrase)

0 commit comments

Comments
 (0)