Skip to content

Commit 06ee06b

Browse files
committed
[java] ensure all tear downs are executed after tests
1 parent 58d7f3c commit 06ee06b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

java/test/org/openqa/selenium/testing/Safely.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222
import java.util.concurrent.CompletableFuture;
2323
import java.util.concurrent.ExecutorService;
2424
import java.util.concurrent.Executors;
25+
import java.util.concurrent.TimeUnit;
26+
import java.util.concurrent.TimeoutException;
27+
import java.util.logging.Level;
28+
import java.util.logging.Logger;
2529

2630
public class Safely {
2731

32+
private static final Logger LOG = Logger.getLogger(Safely.class.getName());
33+
2834
public static void safelyCall(TearDownFixture... fixtures) {
2935
ExecutorService executor = Executors.newFixedThreadPool(fixtures.length);
3036
List<CompletableFuture<Void>> futures = new LinkedList<>();
@@ -44,10 +50,14 @@ public static void safelyCall(TearDownFixture... fixtures) {
4450
futures.add(check);
4551
}
4652

53+
executor.shutdown();
54+
4755
try {
48-
CompletableFuture.allOf(futures.toArray(new CompletableFuture[] {}));
49-
} finally {
50-
executor.shutdownNow();
56+
CompletableFuture.allOf(futures.toArray(new CompletableFuture[] {})).get(2, TimeUnit.MINUTES);
57+
} catch (TimeoutException ex) {
58+
LOG.log(Level.WARNING, "tear down timed out");
59+
} catch (Exception ex) {
60+
LOG.log(Level.WARNING, "tear down failed", ex);
5161
}
5262
}
5363
}

0 commit comments

Comments
 (0)