Skip to content

Commit c7c9da5

Browse files
committed
Consistent atMost period for Awaitility-based tests
Closes gh-32537
1 parent 290a41d commit c7c9da5

File tree

9 files changed

+48
-47
lines changed

9 files changed

+48
-47
lines changed

spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void getMultipleInstances() {
5757
thread2.start();
5858
// Assert
5959
Awaitility.await()
60-
.atMost(500, TimeUnit.MILLISECONDS)
60+
.atMost(5, TimeUnit.SECONDS)
6161
.pollInterval(10, TimeUnit.MILLISECONDS)
6262
.until(() -> (beans[0] != null) && (beans[1] != null));
6363
assertThat(beans[1]).isNotSameAs(beans[0]);

spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void asyncMethodListener() {
339339
context.refresh();
340340
// Assert
341341
Awaitility.await()
342-
.atMost(1, TimeUnit.SECONDS)
342+
.atMost(5, TimeUnit.SECONDS)
343343
.pollInterval(10, TimeUnit.MILLISECONDS)
344344
.until(() -> listenerCalled == 1);
345345
context.close();
@@ -357,7 +357,7 @@ void asyncClassListener() {
357357
context.close();
358358
// Assert
359359
Awaitility.await()
360-
.atMost(1, TimeUnit.SECONDS)
360+
.atMost(5, TimeUnit.SECONDS)
361361
.pollInterval(10, TimeUnit.MILLISECONDS)
362362
.until(() -> listenerCalled == 2);
363363
assertThat(listenerConstructed).isEqualTo(1);
@@ -377,7 +377,7 @@ void asyncPrototypeClassListener() {
377377
context.close();
378378
// Assert
379379
Awaitility.await()
380-
.atMost(1, TimeUnit.SECONDS)
380+
.atMost(5, TimeUnit.SECONDS)
381381
.pollInterval(10, TimeUnit.MILLISECONDS)
382382
.until(() -> listenerCalled == 2);
383383
assertThat(listenerConstructed).isEqualTo(2);

spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void customExecutorBean() {
226226
asyncBean.work();
227227
// Assert
228228
Awaitility.await()
229-
.atMost(500, TimeUnit.MILLISECONDS)
229+
.atMost(5, TimeUnit.SECONDS)
230230
.pollInterval(10, TimeUnit.MILLISECONDS)
231231
.until(() -> asyncBean.getThreadOfExecution() != null);
232232
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
@@ -244,7 +244,7 @@ void customExecutorConfig() {
244244
asyncBean.work();
245245
// Assert
246246
Awaitility.await()
247-
.atMost(500, TimeUnit.MILLISECONDS)
247+
.atMost(5, TimeUnit.SECONDS)
248248
.pollInterval(10, TimeUnit.MILLISECONDS)
249249
.until(() -> asyncBean.getThreadOfExecution() != null);
250250
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
@@ -266,7 +266,7 @@ void customExecutorConfigWithThrowsException() {
266266
asyncBean.fail();
267267
// Assert
268268
Awaitility.await()
269-
.atMost(500, TimeUnit.MILLISECONDS)
269+
.atMost(5, TimeUnit.SECONDS)
270270
.pollInterval(10, TimeUnit.MILLISECONDS)
271271
.untilAsserted(() -> exceptionHandler.assertCalledWith(method, UnsupportedOperationException.class));
272272
ctx.close();
@@ -283,7 +283,7 @@ void customExecutorBeanConfig() {
283283
asyncBean.work();
284284
// Assert
285285
Awaitility.await()
286-
.atMost(500, TimeUnit.MILLISECONDS)
286+
.atMost(5, TimeUnit.SECONDS)
287287
.pollInterval(10, TimeUnit.MILLISECONDS)
288288
.until(() -> asyncBean.getThreadOfExecution() != null);
289289
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Post-");
@@ -305,7 +305,7 @@ void customExecutorBeanConfigWithThrowsException() {
305305
asyncBean.fail();
306306
// Assert
307307
Awaitility.await()
308-
.atMost(500, TimeUnit.MILLISECONDS)
308+
.atMost(5, TimeUnit.SECONDS)
309309
.pollInterval(10, TimeUnit.MILLISECONDS)
310310
.untilAsserted(() -> exceptionHandler.assertCalledWith(method, UnsupportedOperationException.class));
311311
ctx.close();
@@ -320,7 +320,7 @@ public void findOnInterfaceWithInterfaceProxy() {
320320
asyncBean.work();
321321
// Assert
322322
Awaitility.await()
323-
.atMost(500, TimeUnit.MILLISECONDS)
323+
.atMost(5, TimeUnit.SECONDS)
324324
.pollInterval(10, TimeUnit.MILLISECONDS)
325325
.until(() -> asyncBean.getThreadOfExecution() != null);
326326
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
@@ -336,7 +336,7 @@ public void findOnInterfaceWithCglibProxy() {
336336
asyncBean.work();
337337
// Assert
338338
Awaitility.await()
339-
.atMost(500, TimeUnit.MILLISECONDS)
339+
.atMost(5, TimeUnit.SECONDS)
340340
.pollInterval(10, TimeUnit.MILLISECONDS)
341341
.until(() -> asyncBean.getThreadOfExecution() != null);
342342
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");

spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void executeFailingRunnable() {
8989
executor.execute(task);
9090
Awaitility.await()
9191
.dontCatchUncaughtExceptions()
92-
.atMost(1, TimeUnit.SECONDS)
92+
.atMost(5, TimeUnit.SECONDS)
9393
.pollInterval(10, TimeUnit.MILLISECONDS)
9494
.until(() -> task.exception.get() != null && task.exception.get().getMessage().equals(
9595
"TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>"));
@@ -133,7 +133,7 @@ void submitListenableRunnable() {
133133
future.addCallback(result -> outcome = result, ex -> outcome = ex);
134134
// Assert
135135
Awaitility.await()
136-
.atMost(1, TimeUnit.SECONDS)
136+
.atMost(5, TimeUnit.SECONDS)
137137
.pollInterval(10, TimeUnit.MILLISECONDS)
138138
.until(future::isDone);
139139
assertThat(outcome).isNull();
@@ -148,7 +148,7 @@ void submitCompletableRunnable() {
148148
future.whenComplete(this::storeOutcome);
149149
// Assert
150150
Awaitility.await()
151-
.atMost(1, TimeUnit.SECONDS)
151+
.atMost(5, TimeUnit.SECONDS)
152152
.pollInterval(10, TimeUnit.MILLISECONDS)
153153
.until(future::isDone);
154154
assertThat(outcome).isNull();
@@ -164,7 +164,7 @@ void submitFailingListenableRunnable() {
164164

165165
Awaitility.await()
166166
.dontCatchUncaughtExceptions()
167-
.atMost(1, TimeUnit.SECONDS)
167+
.atMost(5, TimeUnit.SECONDS)
168168
.pollInterval(10, TimeUnit.MILLISECONDS)
169169
.until(() -> future.isDone() && outcome != null);
170170
assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
@@ -178,7 +178,7 @@ void submitFailingCompletableRunnable() {
178178

179179
Awaitility.await()
180180
.dontCatchUncaughtExceptions()
181-
.atMost(1, TimeUnit.SECONDS)
181+
.atMost(5, TimeUnit.SECONDS)
182182
.pollInterval(10, TimeUnit.MILLISECONDS)
183183
.until(() -> future.isDone() && outcome != null);
184184
assertThat(outcome.getClass()).isSameAs(CompletionException.class);
@@ -198,7 +198,7 @@ void submitListenableRunnableWithGetAfterShutdown() throws Exception {
198198
// ignore
199199
}
200200
Awaitility.await()
201-
.atMost(4, TimeUnit.SECONDS)
201+
.atMost(5, TimeUnit.SECONDS)
202202
.pollInterval(10, TimeUnit.MILLISECONDS)
203203
.untilAsserted(() -> assertThatExceptionOfType(CancellationException.class)
204204
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
@@ -217,7 +217,7 @@ void submitCompletableRunnableWithGetAfterShutdown() throws Exception {
217217
// ignore
218218
}
219219
Awaitility.await()
220-
.atMost(4, TimeUnit.SECONDS)
220+
.atMost(5, TimeUnit.SECONDS)
221221
.pollInterval(10, TimeUnit.MILLISECONDS)
222222
.untilAsserted(() -> assertThatExceptionOfType(TimeoutException.class)
223223
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
@@ -253,7 +253,7 @@ void submitCallableWithGetAfterShutdown() throws Exception {
253253
// ignore
254254
}
255255
Awaitility.await()
256-
.atMost(4, TimeUnit.SECONDS)
256+
.atMost(5, TimeUnit.SECONDS)
257257
.pollInterval(10, TimeUnit.MILLISECONDS)
258258
.untilAsserted(() -> assertThatExceptionOfType(CancellationException.class)
259259
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
@@ -268,7 +268,7 @@ void submitListenableCallable() {
268268
future.addCallback(result -> outcome = result, ex -> outcome = ex);
269269
// Assert
270270
Awaitility.await()
271-
.atMost(1, TimeUnit.SECONDS)
271+
.atMost(5, TimeUnit.SECONDS)
272272
.pollInterval(10, TimeUnit.MILLISECONDS)
273273
.until(() -> future.isDone() && outcome != null);
274274
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
@@ -284,7 +284,7 @@ void submitFailingListenableCallable() {
284284
// Assert
285285
Awaitility.await()
286286
.dontCatchUncaughtExceptions()
287-
.atMost(1, TimeUnit.SECONDS)
287+
.atMost(5, TimeUnit.SECONDS)
288288
.pollInterval(10, TimeUnit.MILLISECONDS)
289289
.until(() -> future.isDone() && outcome != null);
290290
assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
@@ -310,7 +310,7 @@ void submitCompletableCallable() {
310310
future.whenComplete(this::storeOutcome);
311311
// Assert
312312
Awaitility.await()
313-
.atMost(1, TimeUnit.SECONDS)
313+
.atMost(5, TimeUnit.SECONDS)
314314
.pollInterval(10, TimeUnit.MILLISECONDS)
315315
.until(() -> future.isDone() && outcome != null);
316316
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
@@ -325,7 +325,7 @@ void submitFailingCompletableCallable() {
325325
// Assert
326326
Awaitility.await()
327327
.dontCatchUncaughtExceptions()
328-
.atMost(1, TimeUnit.SECONDS)
328+
.atMost(5, TimeUnit.SECONDS)
329329
.pollInterval(10, TimeUnit.MILLISECONDS)
330330
.until(() -> future.isDone() && outcome != null);
331331
assertThat(outcome.getClass()).isSameAs(CompletionException.class);

spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@SuppressWarnings("unchecked")
4545
class ReactiveAdapterRegistryTests {
4646

47-
private static final Duration ONE_SECOND = Duration.ofSeconds(1);
47+
private static final Duration FIVE_SECONDS = Duration.ofSeconds(5);
4848

4949
private final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
5050

@@ -134,15 +134,15 @@ void toFlux() {
134134
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence);
135135
Object target = getAdapter(Flux.class).fromPublisher(source);
136136
assertThat(target).isInstanceOf(Flux.class);
137-
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
137+
assertThat(((Flux<Integer>) target).collectList().block(FIVE_SECONDS)).isEqualTo(sequence);
138138
}
139139

140140
@Test
141141
void toMono() {
142142
Publisher<Integer> source = io.reactivex.rxjava3.core.Flowable.fromArray(1, 2, 3);
143143
Object target = getAdapter(Mono.class).fromPublisher(source);
144144
assertThat(target).isInstanceOf(Mono.class);
145-
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
145+
assertThat(((Mono<Integer>) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1));
146146
}
147147

148148
@Test
@@ -152,7 +152,7 @@ void toFlowPublisher() {
152152
Object target = getAdapter(Flow.Publisher.class).fromPublisher(source);
153153
assertThat(target).isInstanceOf(Flow.Publisher.class);
154154
assertThat(JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher<Integer>) target)
155-
.collectList().block(ONE_SECOND)).isEqualTo(sequence);
155+
.collectList().block(FIVE_SECONDS)).isEqualTo(sequence);
156156
}
157157

158158
@Test
@@ -169,7 +169,7 @@ void fromCompletableFuture() {
169169
future.complete(1);
170170
Object target = getAdapter(CompletableFuture.class).toPublisher(future);
171171
assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class);
172-
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
172+
assertThat(((Mono<Integer>) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1));
173173
}
174174
}
175175

@@ -227,7 +227,7 @@ void fromFlowable() {
227227
Object source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence);
228228
Object target = getAdapter(io.reactivex.rxjava3.core.Flowable.class).toPublisher(source);
229229
assertThat(target).as("Expected Flux Publisher: " + target.getClass().getName()).isInstanceOf(Flux.class);
230-
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
230+
assertThat(((Flux<Integer>) target).collectList().block(FIVE_SECONDS)).isEqualTo(sequence);
231231
}
232232

233233
@Test
@@ -236,23 +236,23 @@ void fromObservable() {
236236
Object source = io.reactivex.rxjava3.core.Observable.fromIterable(sequence);
237237
Object target = getAdapter(io.reactivex.rxjava3.core.Observable.class).toPublisher(source);
238238
assertThat(target).as("Expected Flux Publisher: " + target.getClass().getName()).isInstanceOf(Flux.class);
239-
assertThat(((Flux<Integer>) target).collectList().block(ONE_SECOND)).isEqualTo(sequence);
239+
assertThat(((Flux<Integer>) target).collectList().block(FIVE_SECONDS)).isEqualTo(sequence);
240240
}
241241

242242
@Test
243243
void fromSingle() {
244244
Object source = io.reactivex.rxjava3.core.Single.just(1);
245245
Object target = getAdapter(io.reactivex.rxjava3.core.Single.class).toPublisher(source);
246246
assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class);
247-
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
247+
assertThat(((Mono<Integer>) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1));
248248
}
249249

250250
@Test
251251
void fromCompletable() {
252252
Object source = io.reactivex.rxjava3.core.Completable.complete();
253253
Object target = getAdapter(io.reactivex.rxjava3.core.Completable.class).toPublisher(source);
254254
assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class);
255-
((Mono<Void>) target).block(ONE_SECOND);
255+
((Mono<Void>) target).block(FIVE_SECONDS);
256256
}
257257
}
258258

@@ -289,15 +289,15 @@ void toUni() {
289289
Publisher<Integer> source = Mono.just(1);
290290
Object target = getAdapter(Uni.class).fromPublisher(source);
291291
assertThat(target).isInstanceOf(Uni.class);
292-
assertThat(((Uni<Integer>) target).await().atMost(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
292+
assertThat(((Uni<Integer>) target).await().atMost(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1));
293293
}
294294

295295
@Test
296296
void fromUni() {
297297
Uni<Integer> source = Uni.createFrom().item(1);
298298
Object target = getAdapter(Uni.class).toPublisher(source);
299299
assertThat(target).isInstanceOf(Mono.class);
300-
assertThat(((Mono<Integer>) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1));
300+
assertThat(((Mono<Integer>) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1));
301301
}
302302

303303
@Test
@@ -306,7 +306,7 @@ void toMulti() {
306306
Publisher<Integer> source = Flux.fromIterable(sequence);
307307
Object target = getAdapter(Multi.class).fromPublisher(source);
308308
assertThat(target).isInstanceOf(Multi.class);
309-
assertThat(((Multi<Integer>) target).collect().asList().await().atMost(ONE_SECOND)).isEqualTo(sequence);
309+
assertThat(((Multi<Integer>) target).collect().asList().await().atMost(FIVE_SECONDS)).isEqualTo(sequence);
310310
}
311311

312312
@Test
@@ -315,7 +315,7 @@ void fromMulti() {
315315
Multi<Integer> source = Multi.createFrom().iterable(sequence);
316316
Object target = getAdapter(Multi.class).toPublisher(source);
317317
assertThat(target).isInstanceOf(Flux.class);
318-
assertThat(((Flux<Integer>) target).blockLast(ONE_SECOND)).isEqualTo(Integer.valueOf(3));
318+
assertThat(((Flux<Integer>) target).blockLast(FIVE_SECONDS)).isEqualTo(Integer.valueOf(3));
319319
}
320320
}
321321

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/JUnitJupiterApplicationEventsIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
1616

1717
package org.springframework.test.context.junit.jupiter.event;
1818

19+
import java.util.concurrent.TimeUnit;
1920
import java.util.stream.Stream;
2021

2122
import org.assertj.core.api.InstanceOfAssertFactories;
2223
import org.awaitility.Awaitility;
23-
import org.awaitility.Durations;
2424
import org.junit.jupiter.api.AfterEach;
2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Nested;
@@ -263,7 +263,7 @@ void asyncPublication() throws InterruptedException {
263263
void asyncConsumption() {
264264
context.publishEvent(new CustomEvent("sync"));
265265

266-
Awaitility.await().atMost(Durations.ONE_SECOND)
266+
Awaitility.await().atMost(5, TimeUnit.SECONDS)
267267
.untilAsserted(() -> assertThat(this.applicationEvents.stream(CustomEvent.class))
268268
.singleElement()
269269
.extracting(CustomEvent::getMessage, InstanceOfAssertFactories.STRING)

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626

2727
import org.assertj.core.api.InstanceOfAssertFactories;
2828
import org.awaitility.Awaitility;
29-
import org.awaitility.Durations;
3029
import org.junit.jupiter.api.AfterEach;
3130
import org.junit.jupiter.api.Test;
3231
import org.junit.jupiter.api.TestInfo;
@@ -221,7 +220,7 @@ void asyncPublication(ApplicationEvents events) throws InterruptedException {
221220
void asyncConsumption() {
222221
this.context.publishEvent("asyncConsumption");
223222

224-
Awaitility.await().atMost(Durations.ONE_SECOND).untilAsserted(() ->//
223+
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() ->//
225224
assertThat(ApplicationEventsHolder//
226225
.getRequiredApplicationEvents()//
227226
.stream()//

0 commit comments

Comments
 (0)