diff options
author | 2024-07-10 20:12:45 +0200 | |
---|---|---|
committer | 2024-07-10 20:12:45 +0200 | |
commit | 83c1598f9abe5b49886fc55cd1d9c8cb8acc4ed2 (patch) | |
tree | 46a467ba1aeed433986fbdb9485a0f5d7079c788 /subprojects | |
parent | build: pin transitive dependencies (diff) | |
download | refinery-83c1598f9abe5b49886fc55cd1d9c8cb8acc4ed2.tar.gz refinery-83c1598f9abe5b49886fc55cd1d9c8cb8acc4ed2.tar.zst refinery-83c1598f9abe5b49886fc55cd1d9c8cb8acc4ed2.zip |
test(web): try to make integration tests less flaky
Diffstat (limited to 'subprojects')
3 files changed, 42 insertions, 29 deletions
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java index 52acee6d..fe4952a9 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java | |||
@@ -17,6 +17,13 @@ public class AwaitTerminationExecutorServiceProvider extends ExecutorServiceProv | |||
17 | private final List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); | 17 | private final List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); |
18 | 18 | ||
19 | @Override | 19 | @Override |
20 | public ExecutorService get(String key) { | ||
21 | synchronized (servicesToShutDown) { | ||
22 | return super.get(key); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | @Override | ||
20 | protected ExecutorService createInstance(String key) { | 27 | protected ExecutorService createInstance(String key) { |
21 | var instance = new RestartableCachedThreadPool(() -> super.createInstance(key)); | 28 | var instance = new RestartableCachedThreadPool(() -> super.createInstance(key)); |
22 | synchronized (servicesToShutDown) { | 29 | synchronized (servicesToShutDown) { |
@@ -35,8 +42,8 @@ public class AwaitTerminationExecutorServiceProvider extends ExecutorServiceProv | |||
35 | 42 | ||
36 | @Override | 43 | @Override |
37 | public void dispose() { | 44 | public void dispose() { |
38 | super.dispose(); | ||
39 | synchronized (servicesToShutDown) { | 45 | synchronized (servicesToShutDown) { |
46 | super.dispose(); | ||
40 | for (var executorService : servicesToShutDown) { | 47 | for (var executorService : servicesToShutDown) { |
41 | executorService.waitForTermination(); | 48 | executorService.waitForTermination(); |
42 | } | 49 | } |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java index 991ff114..4d55e548 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/RestartableCachedThreadPool.java | |||
@@ -13,29 +13,34 @@ import org.slf4j.LoggerFactory; | |||
13 | import java.util.Collection; | 13 | import java.util.Collection; |
14 | import java.util.List; | 14 | import java.util.List; |
15 | import java.util.concurrent.*; | 15 | import java.util.concurrent.*; |
16 | import java.util.concurrent.atomic.AtomicReference; | ||
16 | 17 | ||
17 | public class RestartableCachedThreadPool implements ExecutorService { | 18 | public class RestartableCachedThreadPool implements ExecutorService { |
18 | private static final Logger LOG = LoggerFactory.getLogger(RestartableCachedThreadPool.class); | 19 | private static final Logger LOG = LoggerFactory.getLogger(RestartableCachedThreadPool.class); |
19 | 20 | ||
20 | private ExecutorService delegate; | 21 | private final AtomicReference<ExecutorService> delegate = new AtomicReference<>(); |
21 | 22 | ||
22 | private final Provider<ExecutorService> executorServiceProvider; | 23 | private final Provider<ExecutorService> executorServiceProvider; |
23 | 24 | ||
24 | public RestartableCachedThreadPool(Provider<ExecutorService> executorServiceProvider) { | 25 | public RestartableCachedThreadPool(Provider<ExecutorService> executorServiceProvider) { |
25 | this.executorServiceProvider = executorServiceProvider; | 26 | this.executorServiceProvider = executorServiceProvider; |
26 | delegate = executorServiceProvider.get(); | 27 | delegate.set(executorServiceProvider.get()); |
27 | } | 28 | } |
28 | 29 | ||
29 | public void waitForAllTasksToFinish() { | 30 | public void waitForAllTasksToFinish() { |
30 | delegate.shutdown(); | 31 | var oldDelegate = delegate.getAndSet(executorServiceProvider.get()); |
31 | waitForTermination(); | 32 | oldDelegate.shutdown(); |
32 | delegate = executorServiceProvider.get(); | 33 | waitForTermination(oldDelegate); |
33 | } | 34 | } |
34 | 35 | ||
35 | public void waitForTermination() { | 36 | public void waitForTermination() { |
37 | waitForTermination(delegate.get()); | ||
38 | } | ||
39 | |||
40 | private static void waitForTermination(ExecutorService executorService) { | ||
36 | boolean result = false; | 41 | boolean result = false; |
37 | try { | 42 | try { |
38 | result = delegate.awaitTermination(10, TimeUnit.SECONDS); | 43 | result = executorService.awaitTermination(10, TimeUnit.SECONDS); |
39 | } catch (InterruptedException e) { | 44 | } catch (InterruptedException e) { |
40 | LOG.warn("Interrupted while waiting for delegate executor to stop", e); | 45 | LOG.warn("Interrupted while waiting for delegate executor to stop", e); |
41 | } | 46 | } |
@@ -46,70 +51,71 @@ public class RestartableCachedThreadPool implements ExecutorService { | |||
46 | 51 | ||
47 | @Override | 52 | @Override |
48 | public boolean awaitTermination(long arg0, @NotNull TimeUnit arg1) throws InterruptedException { | 53 | public boolean awaitTermination(long arg0, @NotNull TimeUnit arg1) throws InterruptedException { |
49 | return delegate.awaitTermination(arg0, arg1); | 54 | return delegate.get().awaitTermination(arg0, arg1); |
50 | } | 55 | } |
51 | 56 | ||
52 | @Override | 57 | @Override |
53 | public void execute(@NotNull Runnable arg0) { | 58 | public void execute(@NotNull Runnable arg0) { |
54 | delegate.execute(arg0); | 59 | delegate.get().execute(arg0); |
55 | } | 60 | } |
56 | 61 | ||
57 | @Override | 62 | @Override |
58 | public <T> List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> arg0, long arg1, | 63 | public <T> @NotNull List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> arg0, long arg1, |
59 | @NotNull TimeUnit arg2) | 64 | @NotNull TimeUnit arg2) |
60 | throws InterruptedException { | 65 | throws InterruptedException { |
61 | return delegate.invokeAll(arg0, arg1, arg2); | 66 | return delegate.get().invokeAll(arg0, arg1, arg2); |
62 | } | 67 | } |
63 | 68 | ||
64 | @Override | 69 | @Override |
65 | public <T> List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> arg0) throws InterruptedException { | 70 | public <T> @NotNull List<Future<T>> invokeAll(@NotNull Collection<? extends Callable<T>> arg0) |
66 | return delegate.invokeAll(arg0); | 71 | throws InterruptedException { |
72 | return delegate.get().invokeAll(arg0); | ||
67 | } | 73 | } |
68 | 74 | ||
69 | @Override | 75 | @Override |
70 | public <T> T invokeAny(@NotNull Collection<? extends Callable<T>> arg0, long arg1, @NotNull TimeUnit arg2) | 76 | public <T> T invokeAny(@NotNull Collection<? extends Callable<T>> arg0, long arg1, @NotNull TimeUnit arg2) |
71 | throws InterruptedException, ExecutionException, TimeoutException { | 77 | throws InterruptedException, ExecutionException, TimeoutException { |
72 | return delegate.invokeAny(arg0, arg1, arg2); | 78 | return delegate.get().invokeAny(arg0, arg1, arg2); |
73 | } | 79 | } |
74 | 80 | ||
75 | @Override | 81 | @Override |
76 | public <T> T invokeAny(@NotNull Collection<? extends Callable<T>> arg0) throws InterruptedException, | 82 | public <T> @NotNull T invokeAny(@NotNull Collection<? extends Callable<T>> arg0) throws InterruptedException, |
77 | ExecutionException { | 83 | ExecutionException { |
78 | return delegate.invokeAny(arg0); | 84 | return delegate.get().invokeAny(arg0); |
79 | } | 85 | } |
80 | 86 | ||
81 | @Override | 87 | @Override |
82 | public boolean isShutdown() { | 88 | public boolean isShutdown() { |
83 | return delegate.isShutdown(); | 89 | return delegate.get().isShutdown(); |
84 | } | 90 | } |
85 | 91 | ||
86 | @Override | 92 | @Override |
87 | public boolean isTerminated() { | 93 | public boolean isTerminated() { |
88 | return delegate.isTerminated(); | 94 | return delegate.get().isTerminated(); |
89 | } | 95 | } |
90 | 96 | ||
91 | @Override | 97 | @Override |
92 | public void shutdown() { | 98 | public void shutdown() { |
93 | delegate.shutdown(); | 99 | delegate.get().shutdown(); |
94 | } | 100 | } |
95 | 101 | ||
96 | @Override | 102 | @Override |
97 | public List<Runnable> shutdownNow() { | 103 | public @NotNull List<Runnable> shutdownNow() { |
98 | return delegate.shutdownNow(); | 104 | return delegate.get().shutdownNow(); |
99 | } | 105 | } |
100 | 106 | ||
101 | @Override | 107 | @Override |
102 | public <T> Future<T> submit(@NotNull Callable<T> arg0) { | 108 | public <T> @NotNull Future<T> submit(@NotNull Callable<T> arg0) { |
103 | return delegate.submit(arg0); | 109 | return delegate.get().submit(arg0); |
104 | } | 110 | } |
105 | 111 | ||
106 | @Override | 112 | @Override |
107 | public <T> Future<T> submit(@NotNull Runnable arg0, T arg1) { | 113 | public <T> @NotNull Future<T> submit(@NotNull Runnable arg0, T arg1) { |
108 | return delegate.submit(arg0, arg1); | 114 | return delegate.get().submit(arg0, arg1); |
109 | } | 115 | } |
110 | 116 | ||
111 | @Override | 117 | @Override |
112 | public Future<?> submit(@NotNull Runnable arg0) { | 118 | public @NotNull Future<?> submit(@NotNull Runnable arg0) { |
113 | return delegate.submit(arg0); | 119 | return delegate.get().submit(arg0); |
114 | } | 120 | } |
115 | } | 121 | } |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java index d45a9d6b..6ccf1760 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java | |||
@@ -18,7 +18,7 @@ import java.util.List; | |||
18 | import static org.junit.jupiter.api.Assertions.fail; | 18 | import static org.junit.jupiter.api.Assertions.fail; |
19 | 19 | ||
20 | public abstract class WebSocketIntegrationTestClient { | 20 | public abstract class WebSocketIntegrationTestClient { |
21 | private static final long TIMEOUT_MILLIS = Duration.ofSeconds(30).toMillis(); | 21 | private static final long TIMEOUT_MILLIS = Duration.ofSeconds(10).toMillis(); |
22 | 22 | ||
23 | private boolean finished = false; | 23 | private boolean finished = false; |
24 | 24 | ||