Skip to content

Commit 428865d

Browse files
request quarantined, disabled and attempt to fix tests list
1 parent ac2ce26 commit 428865d

File tree

11 files changed

+409
-25
lines changed

11 files changed

+409
-25
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public Map<String, Collection<TestIdentifier>> getKnownTestsByModule(
3333
return Collections.emptyMap();
3434
}
3535

36+
@Override
37+
public Map<String, Map<String, Collection<TestIdentifier>>> getTestManagementTestsByModule(
38+
TracerEnvironment tracerEnvironment) {
39+
return Collections.emptyMap();
40+
}
41+
3642
@Override
3743
public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) {
3844
return ChangedFiles.EMPTY;
@@ -50,5 +56,8 @@ Map<String, Collection<TestIdentifier>> getFlakyTestsByModule(TracerEnvironment
5056
Map<String, Collection<TestIdentifier>> getKnownTestsByModule(TracerEnvironment tracerEnvironment)
5157
throws IOException;
5258

59+
Map<String, Map<String, Collection<TestIdentifier>>> getTestManagementTestsByModule(
60+
TracerEnvironment tracerEnvironment) throws IOException;
61+
5362
ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException;
5463
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class ConfigurationApiImpl implements ConfigurationApi {
5454
private static final String CHANGED_FILES_URI = "ci/tests/diffs";
5555
private static final String FLAKY_TESTS_URI = "ci/libraries/tests/flaky";
5656
private static final String KNOWN_TESTS_URI = "ci/libraries/tests";
57+
private static final String TEST_MANAGEMENT_TESTS_URI = "test/libraries/test-management/tests";
5758

5859
private final BackendApi backendApi;
5960
private final CiVisibilityMetricCollector metricCollector;
@@ -63,6 +64,7 @@ public class ConfigurationApiImpl implements ConfigurationApi {
6364
private final JsonAdapter<EnvelopeDto<CiVisibilitySettings>> settingsResponseAdapter;
6465
private final JsonAdapter<MultiEnvelopeDto<TestIdentifierJson>> testIdentifiersResponseAdapter;
6566
private final JsonAdapter<EnvelopeDto<KnownTestsDto>> testFullNamesResponseAdapter;
67+
private final JsonAdapter<EnvelopeDto<TestManagementTestsDto>> testManagementTestsResponseAdapter;
6668
private final JsonAdapter<EnvelopeDto<ChangedFiles>> changedFilesResponseAdapter;
6769

6870
public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector metricCollector) {
@@ -105,6 +107,11 @@ public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector m
105107
ConfigurationApiImpl.class, EnvelopeDto.class, KnownTestsDto.class);
106108
testFullNamesResponseAdapter = moshi.adapter(testFullNamesResponseType);
107109

110+
ParameterizedType testManagementTestsResponseType =
111+
Types.newParameterizedTypeWithOwner(
112+
ConfigurationApiImpl.class, EnvelopeDto.class, TestManagementTestsDto.class);
113+
testManagementTestsResponseAdapter = moshi.adapter(testManagementTestsResponseType);
114+
108115
ParameterizedType changedFilesResponseAdapterType =
109116
Types.newParameterizedTypeWithOwner(
110117
ConfigurationApiImpl.class, EnvelopeDto.class, ChangedFiles.class);
@@ -309,6 +316,90 @@ private Map<String, Collection<TestIdentifier>> parseTestIdentifiers(KnownTestsD
309316
: null;
310317
}
311318

319+
@Override
320+
public Map<String, Map<String, Collection<TestIdentifier>>> getTestManagementTestsByModule(
321+
TracerEnvironment tracerEnvironment) throws IOException {
322+
OkHttpUtils.CustomListener telemetryListener =
323+
new TelemetryListener.Builder(metricCollector)
324+
.requestCount(CiVisibilityCountMetric.TEST_MANAGEMENT_TESTS_DETECTION_REQUEST)
325+
.requestErrors(CiVisibilityCountMetric.TEST_MANAGEMENT_TESTS_DETECTION_REQUEST_ERRORS)
326+
.requestDuration(CiVisibilityDistributionMetric.TEST_MANAGEMENT_TESTS_REQUEST_MS)
327+
.responseBytes(CiVisibilityDistributionMetric.TEST_MANAGEMENT_TESTS_RESPONSE_BYTES)
328+
.build();
329+
330+
String uuid = uuidGenerator.get();
331+
EnvelopeDto<TracerEnvironment> request =
332+
new EnvelopeDto<>(new DataDto<>(uuid, "ci_app_libraries_tests_request", tracerEnvironment));
333+
String json = requestAdapter.toJson(request);
334+
RequestBody requestBody = RequestBody.create(JSON, json);
335+
TestManagementTestsDto testManagementTestsDto =
336+
backendApi.post(
337+
TEST_MANAGEMENT_TESTS_URI,
338+
requestBody,
339+
is ->
340+
testManagementTestsResponseAdapter.fromJson(Okio.buffer(Okio.source(is)))
341+
.data
342+
.attributes,
343+
telemetryListener,
344+
false);
345+
346+
return parseTestManagementTests(testManagementTestsDto);
347+
}
348+
349+
private Map<String, Map<String, Collection<TestIdentifier>>> parseTestManagementTests(
350+
TestManagementTestsDto testsManagementTestsDto) {
351+
int testManagementTestsCount = 0;
352+
353+
Map<String, Collection<TestIdentifier>> quarantinedTestsByModule = new HashMap<>();
354+
Map<String, Collection<TestIdentifier>> disabledTestsByModule = new HashMap<>();
355+
Map<String, Collection<TestIdentifier>> attemptToFixTestsByModule = new HashMap<>();
356+
357+
for (Map.Entry<String, TestManagementTestsDto.Suites> e :
358+
testsManagementTestsDto.getModules().entrySet()) {
359+
String moduleName = e.getKey();
360+
Map<String, TestManagementTestsDto.Tests> testsBySuiteName = e.getValue().getSuites();
361+
362+
for (Map.Entry<String, TestManagementTestsDto.Tests> se : testsBySuiteName.entrySet()) {
363+
String suiteName = se.getKey();
364+
Map<String, TestManagementTestsDto.Properties> tests = se.getValue().getTests();
365+
366+
testManagementTestsCount += tests.size();
367+
368+
for (Map.Entry<String, TestManagementTestsDto.Properties> te : tests.entrySet()) {
369+
String testName = te.getKey();
370+
TestManagementTestsDto.Properties properties = te.getValue();
371+
if (properties.isQuarantined()) {
372+
quarantinedTestsByModule
373+
.computeIfAbsent(moduleName, k -> new HashSet<>())
374+
.add(new TestIdentifier(suiteName, testName, null));
375+
}
376+
if (properties.isDisabled()) {
377+
disabledTestsByModule
378+
.computeIfAbsent(moduleName, k -> new HashSet<>())
379+
.add(new TestIdentifier(suiteName, testName, null));
380+
}
381+
if (properties.isAttemptToFix()) {
382+
attemptToFixTestsByModule
383+
.computeIfAbsent(moduleName, k -> new HashSet<>())
384+
.add(new TestIdentifier(suiteName, testName, null));
385+
}
386+
}
387+
}
388+
}
389+
390+
Map<String, Map<String, Collection<TestIdentifier>>> testsByTypeByModule = new HashMap<>();
391+
testsByTypeByModule.put("quarantined", quarantinedTestsByModule);
392+
testsByTypeByModule.put("disabled", disabledTestsByModule);
393+
testsByTypeByModule.put("attempt_to_fix", attemptToFixTestsByModule);
394+
395+
LOGGER.debug("Received {} test management tests in total", testManagementTestsCount);
396+
metricCollector.add(
397+
CiVisibilityDistributionMetric.TEST_MANAGEMENT_TESTS_RESPONSE_TESTS,
398+
testManagementTestsCount);
399+
400+
return testsByTypeByModule;
401+
}
402+
312403
@Override
313404
public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException {
314405
OkHttpUtils.CustomListener telemetryListener =
@@ -427,4 +518,60 @@ private KnownTestsDto(Map<String, Map<String, List<String>>> tests) {
427518
this.tests = tests;
428519
}
429520
}
521+
522+
private static final class TestManagementTestsDto {
523+
private static final class Properties {
524+
private final Map<String, Boolean> properties;
525+
526+
private Properties(Map<String, Boolean> properties) {
527+
this.properties = properties;
528+
}
529+
530+
public Boolean isQuarantined() {
531+
return properties != null ? properties.getOrDefault("quarantined", false) : false;
532+
}
533+
534+
public Boolean isDisabled() {
535+
return properties != null ? properties.getOrDefault("disabled", false) : false;
536+
}
537+
538+
public Boolean isAttemptToFix() {
539+
return properties != null ? properties.getOrDefault("attempt_to_fix", false) : false;
540+
}
541+
}
542+
543+
private static final class Tests {
544+
private final Map<String, Properties> tests;
545+
546+
private Tests(Map<String, Properties> tests) {
547+
this.tests = tests;
548+
}
549+
550+
public Map<String, Properties> getTests() {
551+
return tests != null ? tests : Collections.emptyMap();
552+
}
553+
}
554+
555+
private static final class Suites {
556+
private final Map<String, Tests> suites;
557+
558+
private Suites(Map<String, Tests> suites) {
559+
this.suites = suites;
560+
}
561+
562+
public Map<String, Tests> getSuites() {
563+
return suites != null ? suites : Collections.emptyMap();
564+
}
565+
}
566+
567+
private final Map<String, Suites> modules;
568+
569+
private TestManagementTestsDto(Map<String, Suites> modules) {
570+
this.modules = modules;
571+
}
572+
573+
public Map<String, Suites> getModules() {
574+
return modules != null ? modules : Collections.emptyMap();
575+
}
576+
}
430577
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettings.java

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ public class ExecutionSettings {
2929
null,
3030
Collections.emptyMap(),
3131
Collections.emptyMap(),
32-
Collections.emptyList(),
3332
null,
3433
null,
34+
Collections.emptyList(),
35+
Collections.emptyList(),
36+
Collections.emptyList(),
3537
LineDiff.EMPTY);
3638

3739
private final boolean itrEnabled;
@@ -44,9 +46,11 @@ public class ExecutionSettings {
4446
@Nullable private final String itrCorrelationId;
4547
@Nonnull private final Map<TestIdentifier, TestMetadata> skippableTests;
4648
@Nonnull private final Map<String, BitSet> skippableTestsCoverage;
47-
@Nonnull private final Collection<TestIdentifier> quarantinedTests;
4849
@Nullable private final Collection<TestIdentifier> flakyTests;
4950
@Nullable private final Collection<TestIdentifier> knownTests;
51+
@Nonnull private final Collection<TestIdentifier> quarantinedTests;
52+
@Nonnull private final Collection<TestIdentifier> disabledTests;
53+
@Nonnull private final Collection<TestIdentifier> attemptToFixTests;
5054
@Nonnull private final Diff pullRequestDiff;
5155

5256
public ExecutionSettings(
@@ -60,9 +64,11 @@ public ExecutionSettings(
6064
@Nullable String itrCorrelationId,
6165
@Nonnull Map<TestIdentifier, TestMetadata> skippableTests,
6266
@Nonnull Map<String, BitSet> skippableTestsCoverage,
63-
@Nonnull Collection<TestIdentifier> quarantinedTests,
6467
@Nullable Collection<TestIdentifier> flakyTests,
6568
@Nullable Collection<TestIdentifier> knownTests,
69+
@Nonnull Collection<TestIdentifier> quarantinedTests,
70+
@Nonnull Collection<TestIdentifier> disabledTests,
71+
@Nonnull Collection<TestIdentifier> attemptToFixTests,
6672
@Nonnull Diff pullRequestDiff) {
6773
this.itrEnabled = itrEnabled;
6874
this.codeCoverageEnabled = codeCoverageEnabled;
@@ -74,9 +80,11 @@ public ExecutionSettings(
7480
this.itrCorrelationId = itrCorrelationId;
7581
this.skippableTests = skippableTests;
7682
this.skippableTestsCoverage = skippableTestsCoverage;
77-
this.quarantinedTests = quarantinedTests;
7883
this.flakyTests = flakyTests;
7984
this.knownTests = knownTests;
85+
this.quarantinedTests = quarantinedTests;
86+
this.disabledTests = disabledTests;
87+
this.attemptToFixTests = attemptToFixTests;
8088
this.pullRequestDiff = pullRequestDiff;
8189
}
8290

@@ -130,11 +138,6 @@ public Map<TestIdentifier, TestMetadata> getSkippableTests() {
130138
return skippableTests;
131139
}
132140

133-
@Nonnull
134-
public Collection<TestIdentifier> getQuarantinedTests() {
135-
return quarantinedTests;
136-
}
137-
138141
/**
139142
* @return the list of known tests for the given module (can be empty), or {@code null} if known
140143
* tests could not be obtained
@@ -153,6 +156,21 @@ public Collection<TestIdentifier> getFlakyTests() {
153156
return flakyTests;
154157
}
155158

159+
@Nonnull
160+
public Collection<TestIdentifier> getQuarantinedTests() {
161+
return quarantinedTests;
162+
}
163+
164+
@Nonnull
165+
public Collection<TestIdentifier> getDisabledTests() {
166+
return disabledTests;
167+
}
168+
169+
@Nonnull
170+
public Collection<TestIdentifier> getAttemptToFixTests() {
171+
return attemptToFixTests;
172+
}
173+
156174
@Nonnull
157175
public Diff getPullRequestDiff() {
158176
return pullRequestDiff;
@@ -175,9 +193,11 @@ public boolean equals(Object o) {
175193
&& Objects.equals(itrCorrelationId, that.itrCorrelationId)
176194
&& Objects.equals(skippableTests, that.skippableTests)
177195
&& Objects.equals(skippableTestsCoverage, that.skippableTestsCoverage)
178-
&& Objects.equals(quarantinedTests, that.quarantinedTests)
179196
&& Objects.equals(flakyTests, that.flakyTests)
180197
&& Objects.equals(knownTests, that.knownTests)
198+
&& Objects.equals(quarantinedTests, that.quarantinedTests)
199+
&& Objects.equals(disabledTests, that.disabledTests)
200+
&& Objects.equals(attemptToFixTests, that.attemptToFixTests)
181201
&& Objects.equals(pullRequestDiff, that.pullRequestDiff);
182202
}
183203

@@ -192,9 +212,11 @@ public int hashCode() {
192212
itrCorrelationId,
193213
skippableTests,
194214
skippableTestsCoverage,
195-
quarantinedTests,
196215
flakyTests,
197216
knownTests,
217+
quarantinedTests,
218+
disabledTests,
219+
attemptToFixTests,
198220
pullRequestDiff);
199221
}
200222

@@ -231,9 +253,11 @@ public static ByteBuffer serialize(ExecutionSettings settings) {
231253
TestMetadataSerializer::serialize);
232254

233255
s.write(settings.skippableTestsCoverage, Serializer::write, Serializer::write);
234-
s.write(settings.quarantinedTests, TestIdentifierSerializer::serialize);
235256
s.write(settings.flakyTests, TestIdentifierSerializer::serialize);
236257
s.write(settings.knownTests, TestIdentifierSerializer::serialize);
258+
s.write(settings.quarantinedTests, TestIdentifierSerializer::serialize);
259+
s.write(settings.disabledTests, TestIdentifierSerializer::serialize);
260+
s.write(settings.attemptToFixTests, TestIdentifierSerializer::serialize);
237261

238262
Diff.SERIALIZER.serialize(settings.pullRequestDiff, s);
239263

@@ -262,12 +286,16 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
262286

263287
Map<String, BitSet> skippableTestsCoverage =
264288
Serializer.readMap(buffer, Serializer::readString, Serializer::readBitSet);
265-
Collection<TestIdentifier> quarantinedTests =
266-
Serializer.readSet(buffer, TestIdentifierSerializer::deserialize);
267289
Collection<TestIdentifier> flakyTests =
268290
Serializer.readSet(buffer, TestIdentifierSerializer::deserialize);
269291
Collection<TestIdentifier> knownTests =
270292
Serializer.readSet(buffer, TestIdentifierSerializer::deserialize);
293+
Collection<TestIdentifier> quarantinedTests =
294+
Serializer.readSet(buffer, TestIdentifierSerializer::deserialize);
295+
Collection<TestIdentifier> disabledTests =
296+
Serializer.readSet(buffer, TestIdentifierSerializer::deserialize);
297+
Collection<TestIdentifier> attemptToFixTests =
298+
Serializer.readSet(buffer, TestIdentifierSerializer::deserialize);
271299

272300
Diff diff = Diff.SERIALIZER.deserialize(buffer);
273301

@@ -282,9 +310,11 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
282310
itrCorrelationId,
283311
skippableTests,
284312
skippableTestsCoverage,
285-
quarantinedTests,
286313
flakyTests,
287314
knownTests,
315+
quarantinedTests,
316+
disabledTests,
317+
attemptToFixTests,
288318
diff);
289319
}
290320
}

0 commit comments

Comments
 (0)