Permalink
Browse files

GeckoDriverService should wait for the geckodriver to be running befo…

…re returning (#2255)
  • Loading branch information...
ngsankha authored and lukeis committed Jun 10, 2016
1 parent 195f9bd commit 44dc930225ae39300270d38188323ff905545038
@@ -17,10 +17,13 @@
package org.openqa.selenium.firefox;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.firefox.internal.Executable;
import org.openqa.selenium.remote.service.DriverService;
@@ -66,7 +69,7 @@ public static GeckoDriverService createDefaultService() {
@Override
protected void waitUntilAvailable() throws MalformedURLException {
return;
PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS);
}
/**
@@ -25,6 +25,7 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.SocketTimeoutException;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@@ -156,4 +157,22 @@ public static boolean pollPort(int port, int timeout, TimeUnit unit) {
return false;
}
public static void waitForPortUp(int port, int timeout, TimeUnit unit) {
long end = System.currentTimeMillis() + unit.toMillis(timeout);
while (System.currentTimeMillis() < end) {
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress("localhost", port), 1000);
socket.close();
return;
} catch (ConnectException e) {
// Ignore this
} catch (SocketTimeoutException e) {
// Ignore this
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}

0 comments on commit 44dc930

Please sign in to comment.