Skip to content

Commit b079a82

Browse files
Pass test source data to retry policy factory
1 parent 8bcee06 commit b079a82

File tree

35 files changed

+330
-255
lines changed

35 files changed

+330
-255
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class TestImpl implements DDTest {
5454
private final long suiteId;
5555
private final Consumer<AgentSpan> onSpanFinish;
5656
private final TestContext context;
57+
private final TestIdentifier identifier;
5758

5859
public TestImpl(
5960
AgentSpanContext moduleSpanContext,
@@ -82,7 +83,7 @@ public TestImpl(
8283
this.suiteId = suiteId;
8384
this.onSpanFinish = onSpanFinish;
8485

85-
TestIdentifier identifier = new TestIdentifier(testSuiteName, testName, testParameters);
86+
this.identifier = new TestIdentifier(testSuiteName, testName, testParameters);
8687
CoverageStore coverageStore = coverageStoreFactory.create(identifier);
8788
CoveragePerTestBridge.setThreadLocalCoverageProbes(coverageStore.getProbes());
8889

@@ -179,6 +180,10 @@ private void populateSourceDataTags(
179180
}
180181
}
181182

183+
public TestIdentifier getIdentifier() {
184+
return identifier;
185+
}
186+
182187
@Override
183188
public void setTag(String key, Object value) {
184189
span.setTag(key, value);

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/events/NoOpTestEventsHandler.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import datadog.trace.api.civisibility.DDTest;
44
import datadog.trace.api.civisibility.DDTestSuite;
55
import datadog.trace.api.civisibility.config.TestIdentifier;
6+
import datadog.trace.api.civisibility.config.TestSourceData;
67
import datadog.trace.api.civisibility.events.TestEventsHandler;
78
import datadog.trace.api.civisibility.retry.TestRetryPolicy;
89
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
910
import datadog.trace.bootstrap.ContextStore;
1011
import datadog.trace.civisibility.retry.NeverRetry;
11-
import java.lang.reflect.Method;
1212
import java.util.Collection;
13+
import javax.annotation.Nonnull;
1314
import org.jetbrains.annotations.NotNull;
1415
import org.jetbrains.annotations.Nullable;
1516

@@ -48,15 +49,12 @@ public void onTestSuiteFinish(SuiteKey descriptor) {
4849
public void onTestStart(
4950
SuiteKey suiteDescriptor,
5051
TestKey descriptor,
51-
String testSuiteName,
5252
String testName,
5353
@Nullable String testFramework,
5454
@Nullable String testFrameworkVersion,
5555
@Nullable String testParameters,
5656
@Nullable Collection<String> categories,
57-
@Nullable Class<?> testClass,
58-
@Nullable String testMethodName,
59-
@Nullable Method testMethod,
57+
@Nonnull TestSourceData testSourceData,
6058
boolean isRetry) {
6159
// do nothing
6260
}
@@ -80,15 +78,12 @@ public void onTestFinish(TestKey descriptor) {
8078
public void onTestIgnore(
8179
SuiteKey suiteDescriptor,
8280
TestKey testDescriptor,
83-
String testSuiteName,
8481
String testName,
8582
@Nullable String testFramework,
8683
@Nullable String testFrameworkVersion,
8784
@Nullable String testParameters,
8885
@Nullable Collection<String> categories,
89-
@Nullable Class<?> testClass,
90-
@Nullable String testMethodName,
91-
@Nullable Method testMethod,
86+
@Nonnull TestSourceData testSourceData,
9287
@Nullable String reason) {
9388
// do nothing
9489
}
@@ -105,7 +100,7 @@ public boolean shouldBeSkipped(TestIdentifier test) {
105100

106101
@NotNull
107102
@Override
108-
public TestRetryPolicy retryPolicy(TestIdentifier test) {
103+
public TestRetryPolicy retryPolicy(TestIdentifier test, TestSourceData source) {
109104
return NeverRetry.INSTANCE;
110105
}
111106

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/events/TestEventsHandlerImpl.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import datadog.trace.api.civisibility.DDTestSuite;
77
import datadog.trace.api.civisibility.InstrumentationBridge;
88
import datadog.trace.api.civisibility.config.TestIdentifier;
9+
import datadog.trace.api.civisibility.config.TestSourceData;
910
import datadog.trace.api.civisibility.events.TestEventsHandler;
1011
import datadog.trace.api.civisibility.retry.TestRetryPolicy;
1112
import datadog.trace.api.civisibility.telemetry.CiVisibilityCountMetric;
@@ -18,7 +19,6 @@
1819
import datadog.trace.civisibility.domain.TestFrameworkSession;
1920
import datadog.trace.civisibility.domain.TestImpl;
2021
import datadog.trace.civisibility.domain.TestSuiteImpl;
21-
import java.lang.reflect.Method;
2222
import java.util.Collection;
2323
import javax.annotation.Nonnull;
2424
import javax.annotation.Nullable;
@@ -125,17 +125,14 @@ public void onTestSuiteFailure(SuiteKey descriptor, @Nullable Throwable throwabl
125125
public void onTestStart(
126126
final SuiteKey suiteDescriptor,
127127
final TestKey descriptor,
128-
final String testSuiteName,
129128
final String testName,
130129
final @Nullable String testFramework,
131130
final @Nullable String testFrameworkVersion,
132131
final @Nullable String testParameters,
133132
final @Nullable Collection<String> categories,
134-
final @Nullable Class<?> testClass,
135-
final @Nullable String testMethodName,
136-
final @Nullable Method testMethod,
133+
final @Nonnull TestSourceData testSourceData,
137134
final boolean isRetry) {
138-
if (skipTrace(testClass)) {
135+
if (skipTrace(testSourceData.getTestClass())) {
139136
return;
140137
}
141138

@@ -148,9 +145,10 @@ public void onTestStart(
148145
+ descriptor);
149146
}
150147

151-
TestImpl test = testSuite.testStart(testName, testParameters, testMethod, null);
148+
TestImpl test =
149+
testSuite.testStart(testName, testParameters, testSourceData.getTestMethod(), null);
152150

153-
TestIdentifier thisTest = new TestIdentifier(testSuiteName, testName, testParameters);
151+
TestIdentifier thisTest = test.getIdentifier();
154152
if (testModule.isNew(thisTest)) {
155153
test.setTag(Tags.TEST_IS_NEW, true);
156154
}
@@ -164,8 +162,11 @@ public void onTestStart(
164162
if (testParameters != null) {
165163
test.setTag(Tags.TEST_PARAMETERS, testParameters);
166164
}
167-
if (testMethodName != null && testMethod != null) {
168-
test.setTag(Tags.TEST_SOURCE_METHOD, testMethodName + Type.getMethodDescriptor(testMethod));
165+
if (testSourceData.getTestMethodName() != null && testSourceData.getTestMethod() != null) {
166+
test.setTag(
167+
Tags.TEST_SOURCE_METHOD,
168+
testSourceData.getTestMethodName()
169+
+ Type.getMethodDescriptor(testSourceData.getTestMethod()));
169170
}
170171
if (categories != null && !categories.isEmpty()) {
171172
test.setTag(Tags.TEST_TRAITS, getTestTraits(categories));
@@ -225,28 +226,22 @@ public void onTestFinish(TestKey descriptor) {
225226
public void onTestIgnore(
226227
final SuiteKey suiteDescriptor,
227228
final TestKey testDescriptor,
228-
final String testSuiteName,
229229
final String testName,
230230
final @Nullable String testFramework,
231231
final @Nullable String testFrameworkVersion,
232232
final @Nullable String testParameters,
233233
final @Nullable Collection<String> categories,
234-
final @Nullable Class<?> testClass,
235-
final @Nullable String testMethodName,
236-
final @Nullable Method testMethod,
234+
@Nonnull TestSourceData testSourceData,
237235
final @Nullable String reason) {
238236
onTestStart(
239237
suiteDescriptor,
240238
testDescriptor,
241-
testSuiteName,
242239
testName,
243240
testFramework,
244241
testFrameworkVersion,
245242
testParameters,
246243
categories,
247-
testClass,
248-
testMethodName,
249-
testMethod,
244+
testSourceData,
250245
false);
251246
onTestSkip(testDescriptor, reason);
252247
onTestFinish(testDescriptor);
@@ -268,7 +263,7 @@ public boolean shouldBeSkipped(TestIdentifier test) {
268263

269264
@Override
270265
@Nonnull
271-
public TestRetryPolicy retryPolicy(TestIdentifier test) {
266+
public TestRetryPolicy retryPolicy(TestIdentifier test, TestSourceData source) {
272267
return testModule.retryPolicy(test);
273268
}
274269

dd-java-agent/instrumentation/junit-4.10/cucumber-junit-4/src/main/java/datadog/trace/instrumentation/junit4/CucumberTracingListener.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.junit4;
22

3+
import datadog.trace.api.civisibility.config.TestSourceData;
34
import datadog.trace.api.civisibility.coverage.CoveragePerTestBridge;
45
import datadog.trace.api.civisibility.events.TestDescriptor;
56
import datadog.trace.api.civisibility.events.TestSuiteDescriptor;
@@ -73,15 +74,12 @@ public void testStarted(final Description description) {
7374
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
7475
new TestSuiteDescriptor(testSuiteName, null),
7576
CucumberUtils.toTestDescriptor(description),
76-
testSuiteName,
7777
testName,
7878
FRAMEWORK_NAME,
7979
FRAMEWORK_VERSION,
8080
null,
8181
categories,
82-
null,
83-
null,
84-
null,
82+
TestSourceData.UNKNOWN,
8583
retryPolicy != null && retryPolicy.currentExecutionIsRetry());
8684

8785
recordFeatureFileCodeCoverage(description);
@@ -164,15 +162,12 @@ public void testIgnored(final Description description) {
164162
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestIgnore(
165163
new TestSuiteDescriptor(testSuiteName, null),
166164
CucumberUtils.toTestDescriptor(description),
167-
testSuiteName,
168165
testName,
169166
FRAMEWORK_NAME,
170167
FRAMEWORK_VERSION,
171168
null,
172169
categories,
173-
null,
174-
null,
175-
null,
170+
TestSourceData.UNKNOWN,
176171
reason);
177172
}
178173
}

dd-java-agent/instrumentation/junit-4.10/cucumber-junit-4/src/main/java/datadog/trace/instrumentation/junit4/retry/Cucumber4RetryInstrumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.agent.tooling.muzzle.Reference;
1010
import datadog.trace.api.Config;
1111
import datadog.trace.api.civisibility.config.TestIdentifier;
12+
import datadog.trace.api.civisibility.config.TestSourceData;
1213
import datadog.trace.api.civisibility.retry.TestRetryPolicy;
1314
import datadog.trace.bootstrap.InstrumentationContext;
1415
import datadog.trace.instrumentation.junit4.CucumberUtils;
@@ -93,7 +94,8 @@ public static Boolean retryIfNeeded(
9394
Description description = CucumberUtils.getPickleRunnerDescription(pickleRunner);
9495
TestIdentifier testIdentifier = CucumberUtils.toTestIdentifier(description);
9596
TestRetryPolicy retryPolicy =
96-
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.retryPolicy(testIdentifier);
97+
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.retryPolicy(
98+
testIdentifier, TestSourceData.UNKNOWN);
9799
if (!retryPolicy.retriesLeft()) {
98100
// retries not applicable, run original method
99101
return null;

dd-java-agent/instrumentation/junit-4.10/munit-junit-4/src/main/java/datadog/trace/instrumentation/junit4/MUnitTracingListener.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,18 @@ public void testSuiteFinished(final Description description) {
7373
public void testStarted(final Description description) {
7474
TestSuiteDescriptor suiteDescriptor = MUnitUtils.toSuiteDescriptor(description);
7575
TestDescriptor testDescriptor = MUnitUtils.toTestDescriptor(description);
76-
String testSuiteName = description.getClassName();
77-
Class<?> testClass = description.getTestClass();
7876
String testName = description.getMethodName();
7977
List<String> categories = getCategories(description);
8078
TestRetryPolicy retryPolicy = retryPolicies.get(description);
8179
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
8280
suiteDescriptor,
8381
testDescriptor,
84-
testSuiteName,
8582
testName,
8683
FRAMEWORK_NAME,
8784
FRAMEWORK_VERSION,
8885
null,
8986
categories,
90-
testClass,
91-
null,
92-
null,
87+
JUnit4Utils.toTestSourceData(description),
9388
retryPolicy != null && retryPolicy.currentExecutionIsRetry());
9489
}
9590

@@ -145,7 +140,6 @@ public void testAssumptionFailure(final Failure failure) {
145140
@Override
146141
public void testIgnored(final Description description) {
147142
Class<?> testClass = description.getTestClass();
148-
String testSuiteName = description.getClassName();
149143
String testName = description.getMethodName();
150144

151145
if (Strings.isNotBlank(testName)) {
@@ -158,15 +152,12 @@ public void testIgnored(final Description description) {
158152
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
159153
suiteDescriptor,
160154
testDescriptor,
161-
testSuiteName,
162155
testName,
163156
FRAMEWORK_NAME,
164157
FRAMEWORK_VERSION,
165158
null,
166159
categories,
167-
testClass,
168-
null,
169-
null,
160+
JUnit4Utils.toTestSourceData(description),
170161
false);
171162
}
172163
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestSkip(testDescriptor, null);
@@ -178,6 +169,7 @@ public void testIgnored(final Description description) {
178169
boolean suiteStarted = isSpanInProgress(InternalSpanTypes.TEST_SUITE_END);
179170
if (!suiteStarted) {
180171
// there is a bug in MUnit 1.0.1+: start/finish events are not fired for skipped suites
172+
String testSuiteName = description.getClassName();
181173
List<String> categories = getCategories(description);
182174
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestSuiteStart(
183175
suiteDescriptor,
@@ -214,22 +206,17 @@ private static boolean isSpanInProgress(UTF8BytesString type) {
214206
private void testCaseIgnored(final Description description) {
215207
TestSuiteDescriptor suiteDescriptor = MUnitUtils.toSuiteDescriptor(description);
216208
TestDescriptor testDescriptor = MUnitUtils.toTestDescriptor(description);
217-
String testSuiteName = description.getClassName();
218209
String testName = description.getMethodName();
219-
Class<?> testClass = description.getTestClass();
220210
List<String> categories = getCategories(description);
221211
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestIgnore(
222212
suiteDescriptor,
223213
testDescriptor,
224-
testSuiteName,
225214
testName,
226215
FRAMEWORK_NAME,
227216
FRAMEWORK_VERSION,
228217
null,
229218
categories,
230-
testClass,
231-
null,
232-
null,
219+
JUnit4Utils.toTestSourceData(description),
233220
null);
234221
}
235222

dd-java-agent/instrumentation/junit-4.10/munit-junit-4/src/main/java/datadog/trace/instrumentation/junit4/retry/MUnitRetryInstrumentation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import datadog.trace.agent.tooling.InstrumenterModule;
99
import datadog.trace.api.Config;
1010
import datadog.trace.api.civisibility.config.TestIdentifier;
11+
import datadog.trace.api.civisibility.config.TestSourceData;
1112
import datadog.trace.api.civisibility.retry.TestRetryPolicy;
1213
import datadog.trace.bootstrap.InstrumentationContext;
1314
import datadog.trace.instrumentation.junit4.JUnit4Utils;
@@ -84,8 +85,10 @@ public static Future<?> retryIfNeeded(
8485

8586
Description description = MUnitUtils.createDescription(runner, test);
8687
TestIdentifier testIdentifier = JUnit4Utils.toTestIdentifier(description);
88+
TestSourceData testSourceData = JUnit4Utils.toTestSourceData(description);
89+
8790
TestRetryPolicy retryPolicy =
88-
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.retryPolicy(testIdentifier);
91+
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.retryPolicy(testIdentifier, testSourceData);
8992
if (!retryPolicy.retriesLeft()) {
9093
// retries not applicable, run original method
9194
return null;

0 commit comments

Comments
 (0)