Skip to content

Commit 51829d3

Browse files
Pass test source data to retry policy factory
1 parent 441582a commit 51829d3

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 javax.annotation.Nullable;
1415
import org.jetbrains.annotations.NotNull;
1516

@@ -49,15 +50,12 @@ public void onTestSuiteFinish(SuiteKey descriptor, @Nullable Long endTime) {
4950
public void onTestStart(
5051
SuiteKey suiteDescriptor,
5152
TestKey descriptor,
52-
String testSuiteName,
5353
String testName,
5454
@Nullable String testFramework,
5555
@Nullable String testFrameworkVersion,
5656
@Nullable String testParameters,
5757
@Nullable Collection<String> categories,
58-
@Nullable Class<?> testClass,
59-
@Nullable String testMethodName,
60-
@Nullable Method testMethod,
58+
@Nonnull TestSourceData testSourceData,
6159
boolean isRetry,
6260
@Nullable Long startTime) {
6361
// do nothing
@@ -82,15 +80,12 @@ public void onTestFinish(TestKey descriptor, @Nullable Long endTime) {
8280
public void onTestIgnore(
8381
SuiteKey suiteDescriptor,
8482
TestKey testDescriptor,
85-
String testSuiteName,
8683
String testName,
8784
@Nullable String testFramework,
8885
@Nullable String testFrameworkVersion,
8986
@Nullable String testParameters,
9087
@Nullable Collection<String> categories,
91-
@Nullable Class<?> testClass,
92-
@Nullable String testMethodName,
93-
@Nullable Method testMethod,
88+
@Nonnull TestSourceData testSourceData,
9489
@Nullable String reason) {
9590
// do nothing
9691
}
@@ -107,7 +102,7 @@ public boolean shouldBeSkipped(TestIdentifier test) {
107102

108103
@NotNull
109104
@Override
110-
public TestRetryPolicy retryPolicy(TestIdentifier test) {
105+
public TestRetryPolicy retryPolicy(TestIdentifier test, TestSourceData source) {
111106
return NeverRetry.INSTANCE;
112107
}
113108

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;
@@ -131,18 +131,15 @@ public void onTestSuiteFailure(SuiteKey descriptor, @Nullable Throwable throwabl
131131
public void onTestStart(
132132
final SuiteKey suiteDescriptor,
133133
final TestKey descriptor,
134-
final String testSuiteName,
135134
final String testName,
136135
final @Nullable String testFramework,
137136
final @Nullable String testFrameworkVersion,
138137
final @Nullable String testParameters,
139138
final @Nullable Collection<String> categories,
140-
final @Nullable Class<?> testClass,
141-
final @Nullable String testMethodName,
142-
final @Nullable Method testMethod,
139+
final @Nonnull TestSourceData testSourceData,
143140
final boolean isRetry,
144141
@Nullable Long startTime) {
145-
if (skipTrace(testClass)) {
142+
if (skipTrace(testSourceData.getTestClass())) {
146143
return;
147144
}
148145

@@ -155,9 +152,10 @@ public void onTestStart(
155152
+ descriptor);
156153
}
157154

158-
TestImpl test = testSuite.testStart(testName, testParameters, testMethod, startTime);
155+
TestImpl test =
156+
testSuite.testStart(testName, testParameters, testSourceData.getTestMethod(), startTime);
159157

160-
TestIdentifier thisTest = new TestIdentifier(testSuiteName, testName, testParameters);
158+
TestIdentifier thisTest = test.getIdentifier();
161159
if (testModule.isNew(thisTest)) {
162160
test.setTag(Tags.TEST_IS_NEW, true);
163161
}
@@ -171,8 +169,11 @@ public void onTestStart(
171169
if (testParameters != null) {
172170
test.setTag(Tags.TEST_PARAMETERS, testParameters);
173171
}
174-
if (testMethodName != null && testMethod != null) {
175-
test.setTag(Tags.TEST_SOURCE_METHOD, testMethodName + Type.getMethodDescriptor(testMethod));
172+
if (testSourceData.getTestMethodName() != null && testSourceData.getTestMethod() != null) {
173+
test.setTag(
174+
Tags.TEST_SOURCE_METHOD,
175+
testSourceData.getTestMethodName()
176+
+ Type.getMethodDescriptor(testSourceData.getTestMethod()));
176177
}
177178
if (categories != null && !categories.isEmpty()) {
178179
test.setTag(Tags.TEST_TRAITS, getTestTraits(categories));
@@ -232,28 +233,22 @@ public void onTestFinish(TestKey descriptor, @Nullable Long endTime) {
232233
public void onTestIgnore(
233234
final SuiteKey suiteDescriptor,
234235
final TestKey testDescriptor,
235-
final String testSuiteName,
236236
final String testName,
237237
final @Nullable String testFramework,
238238
final @Nullable String testFrameworkVersion,
239239
final @Nullable String testParameters,
240240
final @Nullable Collection<String> categories,
241-
final @Nullable Class<?> testClass,
242-
final @Nullable String testMethodName,
243-
final @Nullable Method testMethod,
241+
@Nonnull TestSourceData testSourceData,
244242
final @Nullable String reason) {
245243
onTestStart(
246244
suiteDescriptor,
247245
testDescriptor,
248-
testSuiteName,
249246
testName,
250247
testFramework,
251248
testFrameworkVersion,
252249
testParameters,
253250
categories,
254-
testClass,
255-
testMethodName,
256-
testMethod,
251+
testSourceData,
257252
false,
258253
null);
259254
onTestSkip(testDescriptor, reason);
@@ -272,7 +267,7 @@ public boolean shouldBeSkipped(TestIdentifier test) {
272267

273268
@Override
274269
@Nonnull
275-
public TestRetryPolicy retryPolicy(TestIdentifier test) {
270+
public TestRetryPolicy retryPolicy(TestIdentifier test, TestSourceData source) {
276271
return testModule.retryPolicy(test);
277272
}
278273

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;
@@ -74,15 +75,12 @@ public void testStarted(final Description description) {
7475
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
7576
new TestSuiteDescriptor(testSuiteName, null),
7677
CucumberUtils.toTestDescriptor(description),
77-
testSuiteName,
7878
testName,
7979
FRAMEWORK_NAME,
8080
FRAMEWORK_VERSION,
8181
null,
8282
categories,
83-
null,
84-
null,
85-
null,
83+
TestSourceData.UNKNOWN,
8684
retryPolicy != null && retryPolicy.currentExecutionIsRetry(),
8785
null);
8886

@@ -167,15 +165,12 @@ public void testIgnored(final Description description) {
167165
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestIgnore(
168166
new TestSuiteDescriptor(testSuiteName, null),
169167
CucumberUtils.toTestDescriptor(description),
170-
testSuiteName,
171168
testName,
172169
FRAMEWORK_NAME,
173170
FRAMEWORK_VERSION,
174171
null,
175172
categories,
176-
null,
177-
null,
178-
null,
173+
TestSourceData.UNKNOWN,
179174
reason);
180175
}
181176
}

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
@@ -74,23 +74,18 @@ public void testSuiteFinished(final Description description) {
7474
public void testStarted(final Description description) {
7575
TestSuiteDescriptor suiteDescriptor = MUnitUtils.toSuiteDescriptor(description);
7676
TestDescriptor testDescriptor = MUnitUtils.toTestDescriptor(description);
77-
String testSuiteName = description.getClassName();
78-
Class<?> testClass = description.getTestClass();
7977
String testName = description.getMethodName();
8078
List<String> categories = getCategories(description);
8179
TestRetryPolicy retryPolicy = retryPolicies.get(description);
8280
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
8381
suiteDescriptor,
8482
testDescriptor,
85-
testSuiteName,
8683
testName,
8784
FRAMEWORK_NAME,
8885
FRAMEWORK_VERSION,
8986
null,
9087
categories,
91-
testClass,
92-
null,
93-
null,
88+
JUnit4Utils.toTestSourceData(description),
9489
retryPolicy != null && retryPolicy.currentExecutionIsRetry(),
9590
null);
9691
}
@@ -147,7 +142,6 @@ public void testAssumptionFailure(final Failure failure) {
147142
@Override
148143
public void testIgnored(final Description description) {
149144
Class<?> testClass = description.getTestClass();
150-
String testSuiteName = description.getClassName();
151145
String testName = description.getMethodName();
152146

153147
if (Strings.isNotBlank(testName)) {
@@ -160,15 +154,12 @@ public void testIgnored(final Description description) {
160154
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
161155
suiteDescriptor,
162156
testDescriptor,
163-
testSuiteName,
164157
testName,
165158
FRAMEWORK_NAME,
166159
FRAMEWORK_VERSION,
167160
null,
168161
categories,
169-
testClass,
170-
null,
171-
null,
162+
JUnit4Utils.toTestSourceData(description),
172163
false,
173164
null);
174165
}
@@ -181,6 +172,7 @@ public void testIgnored(final Description description) {
181172
boolean suiteStarted = isSpanInProgress(InternalSpanTypes.TEST_SUITE_END);
182173
if (!suiteStarted) {
183174
// there is a bug in MUnit 1.0.1+: start/finish events are not fired for skipped suites
175+
String testSuiteName = description.getClassName();
184176
List<String> categories = getCategories(description);
185177
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestSuiteStart(
186178
suiteDescriptor,
@@ -218,22 +210,17 @@ private static boolean isSpanInProgress(UTF8BytesString type) {
218210
private void testCaseIgnored(final Description description) {
219211
TestSuiteDescriptor suiteDescriptor = MUnitUtils.toSuiteDescriptor(description);
220212
TestDescriptor testDescriptor = MUnitUtils.toTestDescriptor(description);
221-
String testSuiteName = description.getClassName();
222213
String testName = description.getMethodName();
223-
Class<?> testClass = description.getTestClass();
224214
List<String> categories = getCategories(description);
225215
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestIgnore(
226216
suiteDescriptor,
227217
testDescriptor,
228-
testSuiteName,
229218
testName,
230219
FRAMEWORK_NAME,
231220
FRAMEWORK_VERSION,
232221
null,
233222
categories,
234-
testClass,
235-
null,
236-
null,
223+
JUnit4Utils.toTestSourceData(description),
237224
null);
238225
}
239226

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)