From c7c9da56dacc13503579c53f4c5b94415324b108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 26 Mar 2024 17:44:27 +0100 Subject: [PATCH] Consistent atMost period for Awaitility-based tests Closes gh-32537 --- .../support/SimpleThreadScopeTests.java | 2 +- .../annotation/AsyncExecutionTests.java | 6 ++--- .../annotation/EnableAsyncTests.java | 14 +++++----- .../AbstractSchedulingTaskExecutorTests.java | 24 ++++++++--------- .../core/ReactiveAdapterRegistryTests.java | 26 +++++++++---------- ...iterApplicationEventsIntegrationTests.java | 6 ++--- ...llelApplicationEventsIntegrationTests.java | 5 ++-- ...pplicationEventsAsyncIntegrationTests.java | 7 ++--- ...pplicationEventsAsyncIntegrationTests.java | 5 ++-- 9 files changed, 48 insertions(+), 47 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java b/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java index 64b21891655..5693581fe93 100644 --- a/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java @@ -57,7 +57,7 @@ class SimpleThreadScopeTests { thread2.start(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> (beans[0] != null) && (beans[1] != null)); assertThat(beans[1]).isNotSameAs(beans[0]); diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java index 9774b930b72..074dd0ce971 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java @@ -339,7 +339,7 @@ class AsyncExecutionTests { context.refresh(); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> listenerCalled == 1); context.close(); @@ -357,7 +357,7 @@ class AsyncExecutionTests { context.close(); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> listenerCalled == 2); assertThat(listenerConstructed).isEqualTo(1); @@ -377,7 +377,7 @@ class AsyncExecutionTests { context.close(); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> listenerCalled == 2); assertThat(listenerConstructed).isEqualTo(2); diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java index c5e262dc3c4..1df89b1d03d 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java @@ -226,7 +226,7 @@ class EnableAsyncTests { asyncBean.work(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> asyncBean.getThreadOfExecution() != null); assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-"); @@ -244,7 +244,7 @@ class EnableAsyncTests { asyncBean.work(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> asyncBean.getThreadOfExecution() != null); assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-"); @@ -266,7 +266,7 @@ class EnableAsyncTests { asyncBean.fail(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .untilAsserted(() -> exceptionHandler.assertCalledWith(method, UnsupportedOperationException.class)); ctx.close(); @@ -283,7 +283,7 @@ class EnableAsyncTests { asyncBean.work(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> asyncBean.getThreadOfExecution() != null); assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Post-"); @@ -305,7 +305,7 @@ class EnableAsyncTests { asyncBean.fail(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .untilAsserted(() -> exceptionHandler.assertCalledWith(method, UnsupportedOperationException.class)); ctx.close(); @@ -320,7 +320,7 @@ class EnableAsyncTests { asyncBean.work(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> asyncBean.getThreadOfExecution() != null); assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-"); @@ -336,7 +336,7 @@ class EnableAsyncTests { asyncBean.work(); // Assert Awaitility.await() - .atMost(500, TimeUnit.MILLISECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> asyncBean.getThreadOfExecution() != null); assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-"); diff --git a/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java b/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java index 68f1d80a7cf..5d817ee9e16 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java @@ -89,7 +89,7 @@ abstract class AbstractSchedulingTaskExecutorTests { executor.execute(task); Awaitility.await() .dontCatchUncaughtExceptions() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> task.exception.get() != null && task.exception.get().getMessage().equals( "TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>")); @@ -133,7 +133,7 @@ abstract class AbstractSchedulingTaskExecutorTests { future.addCallback(result -> outcome = result, ex -> outcome = ex); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(future::isDone); assertThat(outcome).isNull(); @@ -148,7 +148,7 @@ abstract class AbstractSchedulingTaskExecutorTests { future.whenComplete(this::storeOutcome); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(future::isDone); assertThat(outcome).isNull(); @@ -164,7 +164,7 @@ abstract class AbstractSchedulingTaskExecutorTests { Awaitility.await() .dontCatchUncaughtExceptions() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> future.isDone() && outcome != null); assertThat(outcome.getClass()).isSameAs(RuntimeException.class); @@ -178,7 +178,7 @@ abstract class AbstractSchedulingTaskExecutorTests { Awaitility.await() .dontCatchUncaughtExceptions() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> future.isDone() && outcome != null); assertThat(outcome.getClass()).isSameAs(CompletionException.class); @@ -198,7 +198,7 @@ abstract class AbstractSchedulingTaskExecutorTests { // ignore } Awaitility.await() - .atMost(4, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThatExceptionOfType(CancellationException.class) .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS))); @@ -217,7 +217,7 @@ abstract class AbstractSchedulingTaskExecutorTests { // ignore } Awaitility.await() - .atMost(4, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThatExceptionOfType(TimeoutException.class) .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS))); @@ -253,7 +253,7 @@ abstract class AbstractSchedulingTaskExecutorTests { // ignore } Awaitility.await() - .atMost(4, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThatExceptionOfType(CancellationException.class) .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS))); @@ -268,7 +268,7 @@ abstract class AbstractSchedulingTaskExecutorTests { future.addCallback(result -> outcome = result, ex -> outcome = ex); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> future.isDone() && outcome != null); assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); @@ -284,7 +284,7 @@ abstract class AbstractSchedulingTaskExecutorTests { // Assert Awaitility.await() .dontCatchUncaughtExceptions() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> future.isDone() && outcome != null); assertThat(outcome.getClass()).isSameAs(RuntimeException.class); @@ -310,7 +310,7 @@ abstract class AbstractSchedulingTaskExecutorTests { future.whenComplete(this::storeOutcome); // Assert Awaitility.await() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> future.isDone() && outcome != null); assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); @@ -325,7 +325,7 @@ abstract class AbstractSchedulingTaskExecutorTests { // Assert Awaitility.await() .dontCatchUncaughtExceptions() - .atMost(1, TimeUnit.SECONDS) + .atMost(5, TimeUnit.SECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> future.isDone() && outcome != null); assertThat(outcome.getClass()).isSameAs(CompletionException.class); diff --git a/spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java b/spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java index 6031d785984..db129ea74f3 100644 --- a/spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java +++ b/spring-core/src/test/java/org/springframework/core/ReactiveAdapterRegistryTests.java @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat; @SuppressWarnings("unchecked") class ReactiveAdapterRegistryTests { - private static final Duration ONE_SECOND = Duration.ofSeconds(1); + private static final Duration FIVE_SECONDS = Duration.ofSeconds(5); private final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); @@ -134,7 +134,7 @@ class ReactiveAdapterRegistryTests { Publisher source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence); Object target = getAdapter(Flux.class).fromPublisher(source); assertThat(target).isInstanceOf(Flux.class); - assertThat(((Flux) target).collectList().block(ONE_SECOND)).isEqualTo(sequence); + assertThat(((Flux) target).collectList().block(FIVE_SECONDS)).isEqualTo(sequence); } @Test @@ -142,7 +142,7 @@ class ReactiveAdapterRegistryTests { Publisher source = io.reactivex.rxjava3.core.Flowable.fromArray(1, 2, 3); Object target = getAdapter(Mono.class).fromPublisher(source); assertThat(target).isInstanceOf(Mono.class); - assertThat(((Mono) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1)); + assertThat(((Mono) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1)); } @Test @@ -152,7 +152,7 @@ class ReactiveAdapterRegistryTests { Object target = getAdapter(Flow.Publisher.class).fromPublisher(source); assertThat(target).isInstanceOf(Flow.Publisher.class); assertThat(JdkFlowAdapter.flowPublisherToFlux((Flow.Publisher) target) - .collectList().block(ONE_SECOND)).isEqualTo(sequence); + .collectList().block(FIVE_SECONDS)).isEqualTo(sequence); } @Test @@ -169,7 +169,7 @@ class ReactiveAdapterRegistryTests { future.complete(1); Object target = getAdapter(CompletableFuture.class).toPublisher(future); assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class); - assertThat(((Mono) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1)); + assertThat(((Mono) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1)); } } @@ -227,7 +227,7 @@ class ReactiveAdapterRegistryTests { Object source = io.reactivex.rxjava3.core.Flowable.fromIterable(sequence); Object target = getAdapter(io.reactivex.rxjava3.core.Flowable.class).toPublisher(source); assertThat(target).as("Expected Flux Publisher: " + target.getClass().getName()).isInstanceOf(Flux.class); - assertThat(((Flux) target).collectList().block(ONE_SECOND)).isEqualTo(sequence); + assertThat(((Flux) target).collectList().block(FIVE_SECONDS)).isEqualTo(sequence); } @Test @@ -236,7 +236,7 @@ class ReactiveAdapterRegistryTests { Object source = io.reactivex.rxjava3.core.Observable.fromIterable(sequence); Object target = getAdapter(io.reactivex.rxjava3.core.Observable.class).toPublisher(source); assertThat(target).as("Expected Flux Publisher: " + target.getClass().getName()).isInstanceOf(Flux.class); - assertThat(((Flux) target).collectList().block(ONE_SECOND)).isEqualTo(sequence); + assertThat(((Flux) target).collectList().block(FIVE_SECONDS)).isEqualTo(sequence); } @Test @@ -244,7 +244,7 @@ class ReactiveAdapterRegistryTests { Object source = io.reactivex.rxjava3.core.Single.just(1); Object target = getAdapter(io.reactivex.rxjava3.core.Single.class).toPublisher(source); assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class); - assertThat(((Mono) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1)); + assertThat(((Mono) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1)); } @Test @@ -252,7 +252,7 @@ class ReactiveAdapterRegistryTests { Object source = io.reactivex.rxjava3.core.Completable.complete(); Object target = getAdapter(io.reactivex.rxjava3.core.Completable.class).toPublisher(source); assertThat(target).as("Expected Mono Publisher: " + target.getClass().getName()).isInstanceOf(Mono.class); - ((Mono) target).block(ONE_SECOND); + ((Mono) target).block(FIVE_SECONDS); } } @@ -289,7 +289,7 @@ class ReactiveAdapterRegistryTests { Publisher source = Mono.just(1); Object target = getAdapter(Uni.class).fromPublisher(source); assertThat(target).isInstanceOf(Uni.class); - assertThat(((Uni) target).await().atMost(ONE_SECOND)).isEqualTo(Integer.valueOf(1)); + assertThat(((Uni) target).await().atMost(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1)); } @Test @@ -297,7 +297,7 @@ class ReactiveAdapterRegistryTests { Uni source = Uni.createFrom().item(1); Object target = getAdapter(Uni.class).toPublisher(source); assertThat(target).isInstanceOf(Mono.class); - assertThat(((Mono) target).block(ONE_SECOND)).isEqualTo(Integer.valueOf(1)); + assertThat(((Mono) target).block(FIVE_SECONDS)).isEqualTo(Integer.valueOf(1)); } @Test @@ -306,7 +306,7 @@ class ReactiveAdapterRegistryTests { Publisher source = Flux.fromIterable(sequence); Object target = getAdapter(Multi.class).fromPublisher(source); assertThat(target).isInstanceOf(Multi.class); - assertThat(((Multi) target).collect().asList().await().atMost(ONE_SECOND)).isEqualTo(sequence); + assertThat(((Multi) target).collect().asList().await().atMost(FIVE_SECONDS)).isEqualTo(sequence); } @Test @@ -315,7 +315,7 @@ class ReactiveAdapterRegistryTests { Multi source = Multi.createFrom().iterable(sequence); Object target = getAdapter(Multi.class).toPublisher(source); assertThat(target).isInstanceOf(Flux.class); - assertThat(((Flux) target).blockLast(ONE_SECOND)).isEqualTo(Integer.valueOf(3)); + assertThat(((Flux) target).blockLast(FIVE_SECONDS)).isEqualTo(Integer.valueOf(3)); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/JUnitJupiterApplicationEventsIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/JUnitJupiterApplicationEventsIntegrationTests.java index ae1d30eeed6..4d646aa6f98 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/JUnitJupiterApplicationEventsIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/JUnitJupiterApplicationEventsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,11 @@ package org.springframework.test.context.junit.jupiter.event; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import org.assertj.core.api.InstanceOfAssertFactories; import org.awaitility.Awaitility; -import org.awaitility.Durations; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; @@ -263,7 +263,7 @@ class JUnitJupiterApplicationEventsIntegrationTests { void asyncConsumption() { context.publishEvent(new CustomEvent("sync")); - Awaitility.await().atMost(Durations.ONE_SECOND) + Awaitility.await().atMost(5, TimeUnit.SECONDS) .untilAsserted(() -> assertThat(this.applicationEvents.stream(CustomEvent.class)) .singleElement() .extracting(CustomEvent::getMessage, InstanceOfAssertFactories.STRING) diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java index 109665bb9ad..d3a8791f114 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/event/ParallelApplicationEventsIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import java.util.stream.Stream; import org.assertj.core.api.InstanceOfAssertFactories; import org.awaitility.Awaitility; -import org.awaitility.Durations; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; @@ -221,7 +220,7 @@ class ParallelApplicationEventsIntegrationTests { void asyncConsumption() { this.context.publishEvent("asyncConsumption"); - Awaitility.await().atMost(Durations.ONE_SECOND).untilAsserted(() ->// + Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() ->// assertThat(ApplicationEventsHolder// .getRequiredApplicationEvents()// .stream()// diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/event/JUnit4ApplicationEventsAsyncIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/event/JUnit4ApplicationEventsAsyncIntegrationTests.java index 3c60c2db6f7..a416690acd6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/event/JUnit4ApplicationEventsAsyncIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/event/JUnit4ApplicationEventsAsyncIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,10 @@ package org.springframework.test.context.junit4.event; +import java.util.concurrent.TimeUnit; + import org.assertj.core.api.InstanceOfAssertFactories; import org.awaitility.Awaitility; -import org.awaitility.Durations; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -70,7 +71,7 @@ public class JUnit4ApplicationEventsAsyncIntegrationTests { public void asyncConsumption() { context.publishEvent(new CustomEvent("sync")); - Awaitility.await().atMost(Durations.ONE_SECOND) + Awaitility.await().atMost(5, TimeUnit.SECONDS) .untilAsserted(() -> assertThat(this.applicationEvents.stream(CustomEvent.class)) .singleElement() .extracting(CustomEvent::getMessage, InstanceOfAssertFactories.STRING) diff --git a/spring-test/src/test/java/org/springframework/test/context/testng/event/TestNGApplicationEventsAsyncIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/testng/event/TestNGApplicationEventsAsyncIntegrationTests.java index 79f60addd13..51e4bc6d046 100644 --- a/spring-test/src/test/java/org/springframework/test/context/testng/event/TestNGApplicationEventsAsyncIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/testng/event/TestNGApplicationEventsAsyncIntegrationTests.java @@ -16,9 +16,10 @@ package org.springframework.test.context.testng.event; +import java.util.concurrent.TimeUnit; + import org.assertj.core.api.InstanceOfAssertFactories; import org.awaitility.Awaitility; -import org.awaitility.Durations; import org.testng.annotations.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -64,7 +65,7 @@ class TestNGApplicationEventsAsyncIntegrationTests extends AbstractTestNGSpringC void asyncConsumption() { context.publishEvent(new CustomEvent("asyncConsumption")); - Awaitility.await().atMost(Durations.ONE_SECOND) + Awaitility.await().atMost(5, TimeUnit.SECONDS) .untilAsserted(() -> assertThat(this.applicationEvents.stream(CustomEvent.class)) .singleElement() .extracting(CustomEvent::getMessage, InstanceOfAssertFactories.STRING)