Skip to content

Commit

Permalink
Adding a timeout to Firefox cleanup process. Fixes issue 7272
Browse files Browse the repository at this point in the history
Signed-off-by: Alexei Barantsev <[email protected]>
  • Loading branch information
menonvarun authored and barancev committed Jun 24, 2014
1 parent 41b8f05 commit 9f3a561
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
16 changes: 15 additions & 1 deletion java/client/src/org/openqa/selenium/firefox/FirefoxBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ public void createProfile(String profileName) throws IOException {
public void waitFor() throws InterruptedException, IOException {
process.waitFor();
}

/**
* Waits for the process to execute, returning the command output taken from the profile's
* execution.
*
* @param timeout the maximum time to wait in milliseconds
* @throws InterruptedException if we are interrupted while waiting for the process to launch
* @throws IOException if there is a problem with reading the input stream of the launching
* process
*/

public void waitFor(long timeout) throws InterruptedException, IOException {
process.waitFor(timeout);
}

/**
* Gets all console output of the binary. Output retrieval is non-destructive and non-blocking.
Expand All @@ -225,7 +239,7 @@ public String getConsoleOutput() throws IOException {
public void clean(FirefoxProfile profile, File profileDir) throws IOException {
startProfile(profile, profileDir, "-silent");
try {
waitFor();
waitFor(timeout);
} catch (InterruptedException e) {
process.destroy();
throw new WebDriverException(e);
Expand Down
8 changes: 8 additions & 0 deletions java/client/src/org/openqa/selenium/os/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public void waitFor() {
throw new WebDriverException(e);
}
}

public void waitFor(long timeout) {
try {
process.waitFor(timeout);
} catch (InterruptedException e) {
throw new WebDriverException(e);
}
}

public boolean isSuccessful() {
return 0 == getExitCode();
Expand Down
2 changes: 2 additions & 0 deletions java/client/src/org/openqa/selenium/os/OsProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface OsProcess {
void executeAsync();

void waitFor() throws InterruptedException;

void waitFor(long timeout) throws InterruptedException;

int destroy();

Expand Down
15 changes: 15 additions & 0 deletions java/client/src/org/openqa/selenium/os/UnixProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ public void waitFor() throws InterruptedException {
handler.waitFor();
}

public void waitFor(long timeout) throws InterruptedException {
long until = System.currentTimeMillis() + timeout;
boolean timedOut = true;
while (System.currentTimeMillis() < until) {
if(handler.hasResult()){
timedOut = false;
break;
}
Thread.sleep(50);
}
if(timedOut){
throw new InterruptedException(String.format("Process timed out after waiting for %d ms.",timeout) );
}
}

public boolean isRunning() {
return !handler.hasResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public void executeAsync() {
public void waitFor() throws InterruptedException {
// no-op
}

public void waitFor(long timeout) throws InterruptedException {
// no-op
}

public int destroy() {
if (!isRunning()) {
Expand Down

0 comments on commit 9f3a561

Please sign in to comment.