From 1e6e5ec2fa44f3fe508fd0289dcea6f326f2351c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Wed, 11 Oct 2023 19:52:03 +0200 Subject: [PATCH] [java] allow a custom timeout when shutting down a process --- .../org/openqa/selenium/os/ExternalProcess.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/java/src/org/openqa/selenium/os/ExternalProcess.java b/java/src/org/openqa/selenium/os/ExternalProcess.java index 632803e7afc1d..fc8b482ca5350 100644 --- a/java/src/org/openqa/selenium/os/ExternalProcess.java +++ b/java/src/org/openqa/selenium/os/ExternalProcess.java @@ -17,7 +17,7 @@ package org.openqa.selenium.os; -import static java.util.concurrent.TimeUnit.SECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.File; import java.io.IOException; @@ -269,11 +269,21 @@ public int exitValue() { * seconds. */ public void shutdown() { + shutdown(Duration.ofSeconds(4)); + } + + /** + * Initiate a normal shutdown of the process or kills it when the process is alive after the given + * timeout. + * + * @param timeout the duration for a process to terminate before destroying it forcibly. + */ + public void shutdown(Duration timeout) { if (process.supportsNormalTermination()) { process.destroy(); try { - if (process.waitFor(4, SECONDS)) { + if (process.waitFor(timeout.toMillis(), MILLISECONDS)) { return; } } catch (InterruptedException ex) {