Skip to content

Commit 0da31f6

Browse files
authored
Separate stdout from stderr to avoid tracer logging from interfering with smoke-test parsing (#8214)
1 parent 0b1e6ff commit 0da31f6

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

dd-smoke-tests/field-injection/src/main/java/datadog/smoketest/fieldinjection/FieldInjectionApp.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public static void main(String... args) {
1515
while (klass != null) {
1616
for (Field field : klass.getDeclaredFields()) {
1717
if (field.getName().startsWith("__datadogContext")) {
18-
System.err.println("___FIELD___:" + className + ":" + field.getName());
18+
System.out.println("___FIELD___:" + className + ":" + field.getName());
1919
}
2020
}
2121
for (Class<?> intf : klass.getInterfaces()) {
22-
System.err.println("___INTERFACE___:" + className + ":" + intf.getName());
22+
System.out.println("___INTERFACE___:" + className + ":" + intf.getName());
2323
}
2424
for (Type genericIntf : klass.getGenericInterfaces()) {
2525
Class<?> intf;
@@ -28,7 +28,7 @@ public static void main(String... args) {
2828
} else {
2929
intf = (Class<?>) genericIntf;
3030
}
31-
System.err.println("___GENERIC_INTERFACE___:" + className + ":" + intf.getName());
31+
System.out.println("___GENERIC_INTERFACE___:" + className + ":" + intf.getName());
3232
}
3333
klass = klass.getSuperclass();
3434
}

dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy

+23-16
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class FieldInjectionSmokeTest extends Specification {
3333
@Shared
3434
protected String shadowJarPath = System.getProperty("datadog.smoketest.agent.shadowJar.path")
3535
@Shared
36-
protected String logFilePath = "${buildDirectory}/reports/testProcess.${this.getClass().getName()}.log"
36+
protected String outFilePath = "${buildDirectory}/reports/testProcess.${this.getClass().getName()}.out.log"
37+
@Shared
38+
protected String errFilePath = "${buildDirectory}/reports/testProcess.${this.getClass().getName()}.err.log"
3739

3840
def "types are injected with expected fields"() {
3941
setup:
@@ -72,21 +74,36 @@ class FieldInjectionSmokeTest extends Specification {
7274
processBuilder.directory(new File(buildDirectory))
7375
processBuilder.environment().put("JAVA_HOME", System.getProperty("java.home"))
7476

75-
Path testOutput = Paths.get(logFilePath)
76-
processBuilder.redirectErrorStream(true)
77-
processBuilder.redirectOutput(testOutput.toFile())
77+
Path testOut = Paths.get(outFilePath)
78+
Path testErr = Paths.get(errFilePath)
79+
processBuilder.redirectOutput(testOut.toFile())
80+
processBuilder.redirectError(testErr.toFile())
7881
Process testedProcess = processBuilder.start()
7982

8083
expect:
8184
testedProcess.waitFor(TIMEOUT_SECS, SECONDS)
8285
testedProcess.exitValue() == 0
83-
List<String> lines = Files.readAllLines(testOutput)
86+
List<String> linesOut = Files.readAllLines(testOut)
87+
List<String> linesErr = Files.readAllLines(testErr)
8488
Map<String, Set<String>> foundTypesAndFields = new HashMap<>()
8589
Map<String, List<String>> foundTypesAndInterfaces = new HashMap<>()
8690
Map<String, List<String>> foundTypesAndGenericInterfaces = new HashMap<>()
8791
Map<String, String> storeFieldAliases = new HashMap<>()
88-
for (String line : lines) {
92+
for (String line : linesErr) {
93+
System.err.println(line)
94+
// extract context-store allocations from tracer logging
95+
Matcher storeAllocation = CONTEXT_STORE_ALLOCATION.matcher(line)
96+
if (storeAllocation.matches()) {
97+
// assertions use context key while internally we use storeId,
98+
// so we need to record the storeId alias for each context key
99+
String storeId = storeAllocation.group(1)
100+
String keyName = storeAllocation.group(2)
101+
storeFieldAliases.put(fieldName(storeId), fieldName(keyName))
102+
}
103+
}
104+
for (String line : linesOut) {
89105
System.out.println(line)
106+
// extract structural info from test application logging
90107
if (line.startsWith("___FIELD___")) {
91108
String[] parts = line.split(":")
92109
parts[2] = storeFieldAliases.get(parts[2])
@@ -97,23 +114,13 @@ class FieldInjectionSmokeTest extends Specification {
97114
} else if (line.startsWith("___GENERIC_INTERFACE___")) {
98115
String[] parts = line.split(":")
99116
foundTypesAndGenericInterfaces.computeIfAbsent(parts[1], { new HashSet<>() }).add(parts[2])
100-
} else {
101-
Matcher storeAllocation = CONTEXT_STORE_ALLOCATION.matcher(line)
102-
if (storeAllocation.matches()) {
103-
// assertions use context key while internally we use storeId,
104-
// so we need to record the storeId alias for each context key
105-
String storeId = storeAllocation.group(1)
106-
String keyName = storeAllocation.group(2)
107-
storeFieldAliases.put(fieldName(storeId), fieldName(keyName))
108-
}
109117
}
110118
}
111119
assert testedTypesAndExpectedFields == foundTypesAndFields
112120
// check same list of names for interfaces and generic interfaces
113121
assert foundTypesAndInterfaces == foundTypesAndGenericInterfaces
114122
}
115123

116-
117124
def fieldName(Class<?> klass) {
118125
return fieldName(klass.getName())
119126
}

0 commit comments

Comments
 (0)