Consistent atMost period for Awaitility-based tests

Closes gh-32537
This commit is contained in:
Stéphane Nicoll
2024-03-26 17:44:27 +01:00
parent 290a41d398
commit c7c9da56da
9 changed files with 48 additions and 47 deletions

View File

@@ -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)

View File

@@ -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()//

View File

@@ -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)

View File

@@ -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)