@@ -105,25 +105,32 @@ public void executeAsync() {
105
105
}
106
106
}
107
107
108
+ public boolean waitForProcessStarted (long duration , TimeUnit unit ) {
109
+ return executeWatchdog .waitForProcessStarted (duration , unit );
110
+ }
111
+
108
112
private OutputStream getOutputStream () {
109
113
return drainTo == null ? inputOut
110
114
: new MultiOutputStream (inputOut , drainTo );
111
115
}
112
116
113
117
public int destroy () {
114
118
SeleniumWatchDog watchdog = executeWatchdog ;
115
- watchdog .waitForProcessStarted ();
116
119
117
- // I literally have no idea why we don't try and kill the process nicely on Windows. If you do,
118
- // answers on the back of a postcard to SeleniumHQ, please.
119
- if (!Platform .getCurrent ().is (WINDOWS )) {
120
- watchdog .destroyProcess ();
121
- watchdog .waitForTerminationAfterDestroy (2 , SECONDS );
122
- }
120
+ if (watchdog .waitForProcessStarted (2 , TimeUnit .MINUTES )) {
121
+ // I literally have no idea why we don't try and kill the process nicely on Windows. If you do,
122
+ // answers on the back of a postcard to SeleniumHQ, please.
123
+ if (!Platform .getCurrent ().is (WINDOWS )) {
124
+ watchdog .destroyProcess ();
125
+ watchdog .waitForTerminationAfterDestroy (2 , SECONDS );
126
+ }
123
127
124
- if (isRunning ()) {
125
- watchdog .destroyHarder ();
126
- watchdog .waitForTerminationAfterDestroy (1 , SECONDS );
128
+ if (isRunning ()) {
129
+ watchdog .destroyHarder ();
130
+ watchdog .waitForTerminationAfterDestroy (1 , SECONDS );
131
+ }
132
+ } else {
133
+ log .warning ("Tried to destory a process which never started." );
127
134
}
128
135
129
136
// Make a best effort to drain the streams.
@@ -236,15 +243,18 @@ public void reset() {
236
243
starting = true ;
237
244
}
238
245
239
- private void waitForProcessStarted () {
240
- while (starting ) {
246
+ private boolean waitForProcessStarted (long duration , TimeUnit unit ) {
247
+ long end = System .currentTimeMillis () + unit .toMillis (duration );
248
+ while (starting && System .currentTimeMillis () < end ) {
241
249
try {
242
250
Thread .sleep (50 );
243
251
} catch (InterruptedException e ) {
244
252
Thread .currentThread ().interrupt ();
245
253
throw new WebDriverException (e );
246
254
}
247
255
}
256
+
257
+ return !starting ;
248
258
}
249
259
250
260
private void waitForTerminationAfterDestroy (int duration , TimeUnit unit ) {
0 commit comments