Skip to content

Commit 4d0376f

Browse files
authored
refactor allure lifecycle for v3 (via #1304)
1 parent 5858b25 commit 4d0376f

119 files changed

Lines changed: 5608 additions & 2790 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/vcs.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Never create pull requests or push git branches without explicit confirmation fr
44

55
## Test Work
66

7-
Use [Allure Test Agent](docs/allure-test-agent.md) for test-related work in this repository.
7+
Use [Allure Agent Mode](docs/allure-agent-mode.md) for test-related work in this repository.
88

9-
- Read `docs/allure-test-agent.md` before designing, writing, reviewing, validating, debugging, or enriching tests.
10-
- Use the `$allure-test-agent` skill as the durable behavior guide when it is installed; this project file contains local commands and conventions.
9+
- Read `docs/allure-agent-mode.md` before designing, writing, reviewing, validating, debugging, or enriching tests.
10+
- Use the `$allure-agent-mode` skill as the durable behavior guide when it is installed; this project file contains local commands and conventions.
1111
- If a command executes tests and its result will be used for smoke checking, reasoning, review, coverage analysis, debugging, or a user-facing conclusion, run it through `allure agent`.
1212
- Use agent-mode execution for smoke checks too, even when the change is small or mechanical.
1313
- If agent output is missing or incomplete, debug that first and treat console-only conclusions as provisional.

allure-assertj/src/main/java/io/qameta/allure/assertj/AllureAspectJ.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@
3838
@Aspect
3939
public class AllureAspectJ {
4040

41-
private static InheritableThreadLocal<AllureLifecycle> lifecycle = new InheritableThreadLocal<AllureLifecycle>() {
42-
@Override
43-
protected AllureLifecycle initialValue() {
44-
return Allure.getLifecycle();
45-
}
46-
};
47-
4841
private static final ThreadLocal<AssertJRecorder> RECORDER = ThreadLocal.withInitial(AssertJRecorder::new);
4942

5043
private static final ThreadLocal<Boolean> RECORDING_MUTED = ThreadLocal.withInitial(() -> false);
@@ -158,27 +151,18 @@ public void softAssertionFailed(final AssertionError error) {
158151
getRecorder().softAssertionFailed(error);
159152
}
160153

161-
/**
162-
* For tests only.
163-
*
164-
* @param allure allure lifecycle to set.
165-
*/
166-
public static void setLifecycle(final AllureLifecycle allure) {
167-
lifecycle.set(allure);
168-
clearContext();
169-
}
170-
171154
/**
172155
* Returns the lifecycle.
173156
*
174157
* @return the Allure lifecycle used by this integration
175158
*/
176159
public static AllureLifecycle getLifecycle() {
177-
return lifecycle.get();
160+
return Allure.getLifecycle();
178161
}
179162

180163
/**
181-
* Handles the clear context callback.
164+
* Drops the calling thread's recorder state. Invoked by {@link AssertJLifecycleListener} at test boundaries so
165+
* chain bookkeeping never accumulates across tests.
182166
*/
183167
public static void clearContext() {
184168
RECORDER.remove();

allure-assertj/src/main/java/io/qameta/allure/assertj/AssertJChain.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616
package io.qameta.allure.assertj;
1717

18+
import io.qameta.allure.AllureExternalKey;
1819
import io.qameta.allure.model.Stage;
1920
import io.qameta.allure.model.Status;
2021
import io.qameta.allure.model.StatusDetails;
2122
import io.qameta.allure.model.StepResult;
2223
import org.assertj.core.api.AbstractAssert;
2324

2425
import java.util.Optional;
25-
import java.util.UUID;
2626

2727
/**
2828
* Parent Allure step for one AssertJ assertion chain.
@@ -69,14 +69,14 @@ final class AssertJChain {
6969

7070
private static final String ASSERTJ_STEP_PREFIX = "assert ";
7171

72-
private final String uuid;
72+
private final AllureExternalKey key;
7373

7474
private final AbstractAssert<?, ?> assertion;
7575

7676
private final StepResult step;
7777

7878
AssertJChain(final AbstractAssert<?, ?> assertion, final String subject) {
79-
this.uuid = UUID.randomUUID().toString();
79+
this.key = AllureExternalKey.random(AllureAspectJ.class);
8080
this.assertion = assertion;
8181
this.step = new StepResult()
8282
.setName(chainName(subject))
@@ -86,8 +86,8 @@ final class AssertJChain {
8686
.setStop(System.currentTimeMillis());
8787
}
8888

89-
String getUuid() {
90-
return uuid;
89+
AllureExternalKey getKey() {
90+
return key;
9191
}
9292

9393
AbstractAssert<?, ?> getAssertion() {

allure-assertj/src/main/java/io/qameta/allure/assertj/AssertJRecorder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ private void attachChain(final AllureLifecycle lifecycle,
187187
final AssertJChain chain,
188188
final AssertJOperation parentOperation) {
189189
if (parentOperation == null) {
190-
lifecycle.startStep(chain.getUuid(), chain.getStep());
191-
lifecycle.stopStep(chain.getUuid());
190+
lifecycle.getCurrentExecutableKey().ifPresent(parent -> {
191+
lifecycle.startStep(parent, chain.getKey(), chain.getStep());
192+
lifecycle.stopStep(chain.getKey());
193+
});
192194
return;
193195
}
194196

allure-assertj/src/test/java/io/qameta/allure/assertj/AllureAspectJTest.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.qameta.allure.model.TestResult;
2323
import io.qameta.allure.test.AllureFeatures;
2424
import io.qameta.allure.test.AllureResults;
25+
import io.qameta.allure.test.IsolatedLifecycle;
2526
import org.assertj.core.api.AbstractStringAssert;
2627
import org.assertj.core.api.InstanceOfAssertFactories;
2728
import org.assertj.core.api.SoftAssertions;
@@ -36,6 +37,7 @@
3637
import static io.qameta.allure.test.RunUtils.runWithinTestContext;
3738
import static org.assertj.core.api.Assertions.assertThat;
3839
import static org.assertj.core.api.Assertions.tuple;
40+
@IsolatedLifecycle
3941
class AllureAspectJTest {
4042

4143
@AllureFeatures.Steps
@@ -44,7 +46,7 @@ void shouldCreateSemanticChainForScalarAssert() {
4446
final AllureResults results = runWithinTestContext(() -> {
4547
assertThat("Data")
4648
.hasSize(4);
47-
}, AllureAspectJ::setLifecycle);
49+
});
4850

4951
final TestResult result = assertOnlyOneResult(results);
5052
assertThat(result.getSteps())
@@ -67,7 +69,7 @@ void shouldUseAssertDescriptionAsChainName() {
6769
assertThat((Object) null)
6870
.as("Nullable object")
6971
.isNull();
70-
}, AllureAspectJ::setLifecycle);
72+
});
7173

7274
final TestResult result = assertOnlyOneResult(results);
7375
assertThat(result.getSteps())
@@ -87,7 +89,7 @@ void shouldRenderByteArraysWithoutPayload() {
8789
assertThat(value.getBytes(StandardCharsets.UTF_8))
8890
.as("Byte array object")
8991
.isEqualTo(value.getBytes(StandardCharsets.UTF_8));
90-
}, AllureAspectJ::setLifecycle);
92+
});
9193

9294
final TestResult result = assertOnlyOneResult(results);
9395
assertThat(result.getSteps())
@@ -105,7 +107,7 @@ void shouldRenderCollectionsAsSubjectsAndExpectedValuesAsValues() {
105107
final AllureResults results = runWithinTestContext(() -> {
106108
assertThat(Arrays.asList("a", "b"))
107109
.containsExactly("a", "b");
108-
}, AllureAspectJ::setLifecycle);
110+
});
109111

110112
final TestResult result = assertOnlyOneResult(results);
111113
assertThat(result.getSteps())
@@ -130,7 +132,7 @@ void shouldRenderSmallArraysAsValues() {
130132

131133
assertThat(new String[]{"alpha", "bravo"})
132134
.containsExactly("alpha", "bravo");
133-
}, AllureAspectJ::setLifecycle);
135+
});
134136

135137
final TestResult result = assertOnlyOneResult(results);
136138
assertThat(result.getSteps())
@@ -156,7 +158,7 @@ void shouldRenderTuplesAsValues() {
156158
tuple("first", Status.PASSED),
157159
tuple("second", Status.FAILED)
158160
);
159-
}, AllureAspectJ::setLifecycle);
161+
});
160162

161163
final TestResult result = assertOnlyOneResult(results);
162164
assertThat(result.getSteps())
@@ -178,7 +180,7 @@ void shouldRenderNullValuesInContainsExactlyInAnyOrder() {
178180
final AllureResults results = runWithinTestContext(() -> {
179181
assertThat(Arrays.asList(null, "a", "b"))
180182
.containsExactlyInAnyOrder(null, "a", "b");
181-
}, AllureAspectJ::setLifecycle);
183+
});
182184

183185
final TestResult result = assertOnlyOneResult(results);
184186
assertThat(result.getSteps())
@@ -203,7 +205,7 @@ void shouldRenderNullValuesAfterExtractingAndKeepLambdaVarargs() {
203205
assertThat(model)
204206
.extracting(TestResult::getDescription, TestResult::getDescriptionHtml)
205207
.containsExactly(null, null);
206-
}, AllureAspectJ::setLifecycle);
208+
});
207209

208210
final TestResult result = assertOnlyOneResult(results);
209211
assertThat(result.getSteps())
@@ -231,7 +233,7 @@ void shouldRenderFieldOrPropertyValueAssertions() {
231233
final AllureResults results = runWithinTestContext(() -> {
232234
assertThat(details)
233235
.hasFieldOrPropertyWithValue("message", "Make the test failed");
234-
}, AllureAspectJ::setLifecycle);
236+
});
235237

236238
final TestResult result = assertOnlyOneResult(results);
237239
assertThat(result.getSteps())
@@ -255,7 +257,7 @@ void shouldTruncateLongStepNamesAndAddOnlyTruncatedValuesAsParameters() {
255257
final AllureResults results = runWithinTestContext(() -> {
256258
assertThat(value)
257259
.isEqualTo(value);
258-
}, AllureAspectJ::setLifecycle);
260+
});
259261

260262
final TestResult result = assertOnlyOneResult(results);
261263
assertThat(result.getSteps())
@@ -294,7 +296,7 @@ void shouldCreateSeparateChainsForMultipleAssertThatCalls() {
294296
assertThat(Arrays.asList("a", "b"))
295297
.hasSize(2)
296298
.contains("a");
297-
}, AllureAspectJ::setLifecycle);
299+
});
298300

299301
final TestResult result = assertOnlyOneResult(results);
300302
assertThat(result.getSteps())
@@ -328,7 +330,7 @@ void shouldAttachOperationsToStoredAssertionInstances() {
328330

329331
a.isEqualTo("alpha");
330332
b.isEqualTo("bravo");
331-
}, AllureAspectJ::setLifecycle);
333+
});
332334

333335
final TestResult result = assertOnlyOneResult(results);
334336
assertThat(result.getSteps())
@@ -361,7 +363,7 @@ void shouldAvoidVerboseModelToStringPayloads() {
361363
assertThat(Collections.singletonList(model))
362364
.hasSize(1)
363365
.containsExactly(model);
364-
}, AllureAspectJ::setLifecycle);
366+
});
365367

366368
final TestResult result = assertOnlyOneResult(results);
367369
assertThat(result.getSteps())
@@ -408,7 +410,7 @@ void shouldKeepNavigationInsideTheSameChain() {
408410
assertThat(Collections.singletonList(Collections.singletonList("delta")))
409411
.flatExtracting(value -> value)
410412
.containsExactly("delta");
411-
}, AllureAspectJ::setLifecycle);
413+
});
412414

413415
final TestResult result = assertOnlyOneResult(results);
414416
assertThat(result.getSteps())
@@ -440,7 +442,7 @@ void shouldRenderSerializedLambdaMethodReferences() {
440442
assertThat(Collections.singletonList(model))
441443
.extracting((Function<TestResult, String> & Serializable) TestResult::getFullName)
442444
.containsExactly("my.company.Test.testOne");
443-
}, AllureAspectJ::setLifecycle);
445+
});
444446

445447
final TestResult result = assertOnlyOneResult(results);
446448
assertThat(result.getSteps())
@@ -458,7 +460,7 @@ void shouldMarkTheFailedHardAssertionOperation() {
458460
final AllureResults results = runWithinTestContext(() -> {
459461
assertThat("Data")
460462
.hasSize(5);
461-
}, AllureAspectJ::setLifecycle);
463+
});
462464

463465
final TestResult result = assertOnlyOneResult(results);
464466
assertThat(result.getSteps())
@@ -486,7 +488,7 @@ void shouldMarkTheFailedSoftAssertionOperationBeforeAssertAll() {
486488
.as("Age")
487489
.isEqualTo(26);
488490
soft.assertAll();
489-
}, AllureAspectJ::setLifecycle);
491+
});
490492

491493
final TestResult result = assertOnlyOneResult(results);
492494
assertThat(result.getSteps())
@@ -518,7 +520,7 @@ void shouldAttachNestedAssertionsUnderCallbackOperations() {
518520
.startsWith("al")
519521
.endsWith("ha")
520522
);
521-
}, AllureAspectJ::setLifecycle);
523+
});
522524

523525
final TestResult result = assertOnlyOneResult(results);
524526
assertThat(result.getSteps())

0 commit comments

Comments
 (0)