Skip to content

Commit 44dc930

Browse files
ngsankhalukeis
authored andcommitted
GeckoDriverService should wait for the geckodriver to be running before returning (#2255)
1 parent 195f9bd commit 44dc930

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

java/client/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
package org.openqa.selenium.firefox;
1919

20+
import static java.util.concurrent.TimeUnit.SECONDS;
21+
2022
import com.google.common.collect.ImmutableList;
2123
import com.google.common.collect.ImmutableMap;
2224

2325
import org.openqa.selenium.WebDriverException;
26+
import org.openqa.selenium.net.PortProber;
2427
import org.openqa.selenium.firefox.internal.Executable;
2528
import org.openqa.selenium.remote.service.DriverService;
2629

@@ -66,7 +69,7 @@ public static GeckoDriverService createDefaultService() {
6669

6770
@Override
6871
protected void waitUntilAvailable() throws MalformedURLException {
69-
return;
72+
PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS);
7073
}
7174

7275
/**

java/client/src/org/openqa/selenium/net/PortProber.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.net.ServerSocket;
2626
import java.net.Socket;
2727
import java.net.UnknownHostException;
28+
import java.net.SocketTimeoutException;
2829
import java.util.Random;
2930
import java.util.concurrent.Callable;
3031
import java.util.concurrent.TimeUnit;
@@ -156,4 +157,22 @@ public static boolean pollPort(int port, int timeout, TimeUnit unit) {
156157

157158
return false;
158159
}
160+
161+
public static void waitForPortUp(int port, int timeout, TimeUnit unit) {
162+
long end = System.currentTimeMillis() + unit.toMillis(timeout);
163+
while (System.currentTimeMillis() < end) {
164+
try {
165+
Socket socket = new Socket();
166+
socket.connect(new InetSocketAddress("localhost", port), 1000);
167+
socket.close();
168+
return;
169+
} catch (ConnectException e) {
170+
// Ignore this
171+
} catch (SocketTimeoutException e) {
172+
// Ignore this
173+
} catch (IOException e) {
174+
throw new RuntimeException(e);
175+
}
176+
}
177+
}
159178
}

0 commit comments

Comments
 (0)