Skip to content

Commit fde1f70

Browse files
committed
wait for running async ops before quit the webclient
1 parent a8cf411 commit fde1f70

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.seleniumhq.selenium</groupId>
77
<artifactId>htmlunit3-driver</artifactId>
8-
<version>4.23.0</version>
8+
<version>4.24.0-SNAPSHOT</version>
99

1010
<name>${project.artifactId}</name>
1111
<description>WebDriver compatible driver for HtmlUnit headless browser</description>

src/main/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,12 +788,31 @@ public void close() {
788788

789789
@Override
790790
public void quit() {
791-
if (webClient_ != null) {
792-
alert_.close();
793-
webClient_.close();
794-
webClient_ = null;
791+
// closing the web client while some async processes are running
792+
// will produce strange effects; therefore wait until they are done
793+
while (runAsyncRunning_) {
794+
try {
795+
Thread.sleep(10);
796+
}
797+
catch (final InterruptedException e) {
798+
throw new RuntimeException(e);
799+
}
800+
}
801+
802+
conditionLock_.lock();
803+
runAsyncRunning_ = true;
804+
try {
805+
if (webClient_ != null) {
806+
alert_.close();
807+
webClient_.close();
808+
webClient_ = null;
809+
}
810+
defaultExecutor_.shutdown();
811+
}
812+
finally {
813+
runAsyncRunning_ = false;
814+
conditionLock_.unlock();
795815
}
796-
defaultExecutor_.shutdown();
797816
}
798817

799818
@Override

src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,15 +543,15 @@ protected WebDriver buildWebDriver() throws IOException {
543543
}
544544
if (webDriver_ == null) {
545545
final HtmlUnitDriverOptions driverOptions = new HtmlUnitDriverOptions(getBrowserVersion());
546-
546+
547547
if (isWebClientCached()) {
548548
driverOptions.setCapability(HtmlUnitOption.optHistorySizeLimit, 0);
549549
}
550-
550+
551551
if (getWebClientTimeout() != null) {
552552
driverOptions.setCapability(HtmlUnitOption.optTimeout, getWebClientTimeout());
553553
}
554-
554+
555555
webDriver_ = new HtmlUnitDriver(driverOptions);
556556
webDriver_.setExecutor(EXECUTOR_POOL);
557557
}

0 commit comments

Comments
 (0)