Skip to content

Commit 9f3a561

Browse files
menonvarunbarancev
authored andcommitted
Adding a timeout to Firefox cleanup process. Fixes issue 7272
Signed-off-by: Alexei Barantsev <[email protected]>
1 parent 41b8f05 commit 9f3a561

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ public void createProfile(String profileName) throws IOException {
207207
public void waitFor() throws InterruptedException, IOException {
208208
process.waitFor();
209209
}
210+
211+
/**
212+
* Waits for the process to execute, returning the command output taken from the profile's
213+
* execution.
214+
*
215+
* @param timeout the maximum time to wait in milliseconds
216+
* @throws InterruptedException if we are interrupted while waiting for the process to launch
217+
* @throws IOException if there is a problem with reading the input stream of the launching
218+
* process
219+
*/
220+
221+
public void waitFor(long timeout) throws InterruptedException, IOException {
222+
process.waitFor(timeout);
223+
}
210224

211225
/**
212226
* Gets all console output of the binary. Output retrieval is non-destructive and non-blocking.
@@ -225,7 +239,7 @@ public String getConsoleOutput() throws IOException {
225239
public void clean(FirefoxProfile profile, File profileDir) throws IOException {
226240
startProfile(profile, profileDir, "-silent");
227241
try {
228-
waitFor();
242+
waitFor(timeout);
229243
} catch (InterruptedException e) {
230244
process.destroy();
231245
throw new WebDriverException(e);

java/client/src/org/openqa/selenium/os/CommandLine.java

+8
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ public void waitFor() {
123123
throw new WebDriverException(e);
124124
}
125125
}
126+
127+
public void waitFor(long timeout) {
128+
try {
129+
process.waitFor(timeout);
130+
} catch (InterruptedException e) {
131+
throw new WebDriverException(e);
132+
}
133+
}
126134

127135
public boolean isSuccessful() {
128136
return 0 == getExitCode();

java/client/src/org/openqa/selenium/os/OsProcess.java

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ interface OsProcess {
3535
void executeAsync();
3636

3737
void waitFor() throws InterruptedException;
38+
39+
void waitFor(long timeout) throws InterruptedException;
3840

3941
int destroy();
4042

java/client/src/org/openqa/selenium/os/UnixProcess.java

+15
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ public void waitFor() throws InterruptedException {
134134
handler.waitFor();
135135
}
136136

137+
public void waitFor(long timeout) throws InterruptedException {
138+
long until = System.currentTimeMillis() + timeout;
139+
boolean timedOut = true;
140+
while (System.currentTimeMillis() < until) {
141+
if(handler.hasResult()){
142+
timedOut = false;
143+
break;
144+
}
145+
Thread.sleep(50);
146+
}
147+
if(timedOut){
148+
throw new InterruptedException(String.format("Process timed out after waiting for %d ms.",timeout) );
149+
}
150+
}
151+
137152
public boolean isRunning() {
138153
return !handler.hasResult();
139154
}

java/client/src/org/openqa/selenium/os/WindowsProcessGroup.java

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public void executeAsync() {
156156
public void waitFor() throws InterruptedException {
157157
// no-op
158158
}
159+
160+
public void waitFor(long timeout) throws InterruptedException {
161+
// no-op
162+
}
159163

160164
public int destroy() {
161165
if (!isRunning()) {

0 commit comments

Comments
 (0)