-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathCiVisibilitySmokeTest.groovy
More file actions
59 lines (50 loc) · 2.75 KB
/
CiVisibilitySmokeTest.groovy
File metadata and controls
59 lines (50 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package datadog.trace.civisibility
import datadog.trace.api.civisibility.config.TestFQN
import spock.lang.Specification
abstract class CiVisibilitySmokeTest extends Specification {
static final List<String> SMOKE_IGNORED_TAGS = ["content.meta.['_dd.integration']"]
protected verifyEventsAndCoverages(String projectName, String toolchain, String toolchainVersion, List<Map<String, Object>> events, List<Map<String, Object>> coverages, List<String> additionalDynamicTags = []) {
def additionalReplacements = ["content.meta.['test.toolchain']": "$toolchain:$toolchainVersion"]
if (System.getenv().get("GENERATE_TEST_FIXTURES") != null) {
def baseTemplatesPath = CiVisibilitySmokeTest.classLoader.getResource(projectName).toURI().schemeSpecificPart.replace('build/resources/test', 'src/test/resources')
CiVisibilityTestUtils.generateTemplates(baseTemplatesPath, events, coverages, additionalReplacements.keySet() + additionalDynamicTags, SMOKE_IGNORED_TAGS)
} else {
CiVisibilityTestUtils.assertData(projectName, events, coverages, additionalReplacements, SMOKE_IGNORED_TAGS, additionalDynamicTags)
}
}
protected test(String suiteName, String testName) {
return new TestFQN(suiteName, testName)
}
protected verifyTestOrder(List<Map<String, Object>> events, List<TestFQN> expectedOrder) {
CiVisibilityTestUtils.assertTestsOrder(events, expectedOrder)
}
/**
* This is a basic sanity check for telemetry metrics.
* It only checks that the reported number of events created and finished is as expected.
* <p>
* Currently the check is not performed for Gradle builds:
* Gradle daemon started with Gradle TestKit outlives the test, so the final telemetry flush happens after the assertions.
*/
protected verifyTelemetryMetrics(List<Map<String, Object>> receivedTelemetryMetrics, List<Map<String, Object>> receivedTelemetryDistributions, int expectedEventsCount) {
int eventsCreated = 0, eventsFinished = 0
for (Map<String, Object> metric : receivedTelemetryMetrics) {
if (metric["metric"] == "event_created") {
for (def point : metric["points"]) {
eventsCreated += point[1]
}
}
if (metric["metric"] == "event_finished") {
for (def point : metric["points"]) {
eventsFinished += point[1]
}
}
}
assert eventsCreated == expectedEventsCount
assert eventsFinished == expectedEventsCount
// an even more basic smoke check for distributions: assert that we received some
assert !receivedTelemetryDistributions.isEmpty()
}
protected verifyCoverageReports(String projectName, List<CiVisibilityTestUtils.CoverageReport> reports, Map<String, String> replacements) {
CiVisibilityTestUtils.assertData(projectName, reports, replacements)
}
}