Skip to content

Commit a207280

Browse files
authored
document how to prevent breaking allure lifecycle for Steps inside Awaitility evaluations (fixes #1135, via #1158)
1 parent 85f3ccd commit a207280

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

allure-awaitility/readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ For more information about awaitility highly recommended look into [awaitility u
77

88

99
### Configuration examples
10-
Single line for all awaitility conditions in project
10+
Single line for all awaitility conditions in project
1111
```java
1212
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
1313
```
1414

15+
And another line to prevent breaking allure lifecycle for Steps inside Awaitility evaluations
16+
```java
17+
Awaitility.pollInSameThread();
18+
```
19+
1520
Moreover, it's possible logging only few unstable conditions with method `.conditionEvaluationListener()`
1621
```java
1722
final AtomicInteger atomicInteger = new AtomicInteger(0);

allure-awaitility/src/test/java/io/qameta/allure/awaitility/ConditionListenersPositiveTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import io.qameta.allure.model.Status;
1919
import io.qameta.allure.model.StepResult;
2020
import io.qameta.allure.model.TestResult;
21+
import org.awaitility.Awaitility;
22+
import org.junit.jupiter.api.BeforeAll;
2123
import org.junit.jupiter.api.DynamicNode;
2224
import org.junit.jupiter.api.DynamicTest;
2325
import org.junit.jupiter.api.Test;
@@ -38,6 +40,11 @@
3840

3941
class ConditionListenersPositiveTest {
4042

43+
@BeforeAll
44+
static void setup() {
45+
Awaitility.pollInSameThread();
46+
}
47+
4148
/**
4249
* Positive test to check proper allure steps generation.
4350
* <p>

allure-awaitility/src/test/java/io/qameta/allure/awaitility/GlobalSettingsNegativeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void reset() {
4848

4949
@BeforeEach
5050
void setup() {
51+
Awaitility.pollInSameThread();
5152
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
5253
}
5354

allure-awaitility/src/test/java/io/qameta/allure/awaitility/GlobalSettingsPositiveTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void reset() {
4848

4949
@BeforeEach
5050
void setup() {
51+
Awaitility.pollInSameThread();
5152
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
5253
}
5354

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2016-2024 Qameta Software Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.awaitility;
17+
18+
import io.qameta.allure.model.Status;
19+
import io.qameta.allure.model.TestResult;
20+
import org.awaitility.Awaitility;
21+
import org.junit.jupiter.api.*;
22+
23+
import java.util.List;
24+
import java.util.stream.Stream;
25+
26+
import static io.qameta.allure.test.RunUtils.runWithinTestContext;
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.awaitility.Awaitility.await;
29+
30+
public class MultipleConditionsTest {
31+
32+
@AfterEach
33+
void reset() {
34+
Awaitility.reset();
35+
}
36+
37+
@BeforeEach
38+
void setup() {
39+
Awaitility.pollInSameThread();
40+
Awaitility.setDefaultConditionEvaluationListener(new AllureAwaitilityListener());
41+
}
42+
43+
@TestFactory
44+
Stream<DynamicNode> bothAwaitilityStepsShouldAppearTest() {
45+
final List<TestResult> testResult = runWithinTestContext(() -> {
46+
await().with()
47+
.alias("First waiting")
48+
.until(() -> true);
49+
await().with()
50+
.alias("Second waiting")
51+
.until(() -> true);
52+
},
53+
AllureAwaitilityListener::setLifecycle
54+
).getTestResults();
55+
56+
return Stream.of(
57+
DynamicTest.dynamicTest("Exactly 2 top level step for 2 awaitility condition", () ->
58+
assertThat(testResult.get(0).getSteps())
59+
.describedAs("Allure TestResult contains exactly 2 top level step for 2 awaitility condition")
60+
.hasSize(2)
61+
),
62+
DynamicTest.dynamicTest("All top level step for all awaitility condition has PASSED", () ->
63+
assertThat(testResult.get(0).getSteps())
64+
.describedAs("Allure TestResult contains all top level step for all awaitility with PASSED condition")
65+
.allMatch(step -> Status.PASSED.equals(step.getStatus()))
66+
)
67+
);
68+
}
69+
70+
}

0 commit comments

Comments
 (0)