From dabecd53488e7de0ea8a13e4f63cbf49b4d6083a Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Wed, 15 Jan 2025 19:42:43 +0000 Subject: [PATCH] Separate stdout from stderr to avoid tracer logging from interfering with smoke-test parsing --- .../fieldinjection/FieldInjectionApp.java | 6 +-- .../smoketest/FieldInjectionSmokeTest.groovy | 39 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/dd-smoke-tests/field-injection/src/main/java/datadog/smoketest/fieldinjection/FieldInjectionApp.java b/dd-smoke-tests/field-injection/src/main/java/datadog/smoketest/fieldinjection/FieldInjectionApp.java index d6554014dba..997f2191da4 100644 --- a/dd-smoke-tests/field-injection/src/main/java/datadog/smoketest/fieldinjection/FieldInjectionApp.java +++ b/dd-smoke-tests/field-injection/src/main/java/datadog/smoketest/fieldinjection/FieldInjectionApp.java @@ -15,11 +15,11 @@ public static void main(String... args) { while (klass != null) { for (Field field : klass.getDeclaredFields()) { if (field.getName().startsWith("__datadogContext")) { - System.err.println("___FIELD___:" + className + ":" + field.getName()); + System.out.println("___FIELD___:" + className + ":" + field.getName()); } } for (Class intf : klass.getInterfaces()) { - System.err.println("___INTERFACE___:" + className + ":" + intf.getName()); + System.out.println("___INTERFACE___:" + className + ":" + intf.getName()); } for (Type genericIntf : klass.getGenericInterfaces()) { Class intf; @@ -28,7 +28,7 @@ public static void main(String... args) { } else { intf = (Class) genericIntf; } - System.err.println("___GENERIC_INTERFACE___:" + className + ":" + intf.getName()); + System.out.println("___GENERIC_INTERFACE___:" + className + ":" + intf.getName()); } klass = klass.getSuperclass(); } diff --git a/dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy b/dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy index 9c0f19fc7be..e321595422c 100644 --- a/dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy +++ b/dd-smoke-tests/field-injection/src/test/groovy/datadog/smoketest/FieldInjectionSmokeTest.groovy @@ -33,7 +33,9 @@ class FieldInjectionSmokeTest extends Specification { @Shared protected String shadowJarPath = System.getProperty("datadog.smoketest.agent.shadowJar.path") @Shared - protected String logFilePath = "${buildDirectory}/reports/testProcess.${this.getClass().getName()}.log" + protected String outFilePath = "${buildDirectory}/reports/testProcess.${this.getClass().getName()}.out.log" + @Shared + protected String errFilePath = "${buildDirectory}/reports/testProcess.${this.getClass().getName()}.err.log" def "types are injected with expected fields"() { setup: @@ -72,21 +74,36 @@ class FieldInjectionSmokeTest extends Specification { processBuilder.directory(new File(buildDirectory)) processBuilder.environment().put("JAVA_HOME", System.getProperty("java.home")) - Path testOutput = Paths.get(logFilePath) - processBuilder.redirectErrorStream(true) - processBuilder.redirectOutput(testOutput.toFile()) + Path testOut = Paths.get(outFilePath) + Path testErr = Paths.get(errFilePath) + processBuilder.redirectOutput(testOut.toFile()) + processBuilder.redirectError(testErr.toFile()) Process testedProcess = processBuilder.start() expect: testedProcess.waitFor(TIMEOUT_SECS, SECONDS) testedProcess.exitValue() == 0 - List lines = Files.readAllLines(testOutput) + List linesOut = Files.readAllLines(testOut) + List linesErr = Files.readAllLines(testErr) Map> foundTypesAndFields = new HashMap<>() Map> foundTypesAndInterfaces = new HashMap<>() Map> foundTypesAndGenericInterfaces = new HashMap<>() Map storeFieldAliases = new HashMap<>() - for (String line : lines) { + for (String line : linesErr) { + System.err.println(line) + // extract context-store allocations from tracer logging + Matcher storeAllocation = CONTEXT_STORE_ALLOCATION.matcher(line) + if (storeAllocation.matches()) { + // assertions use context key while internally we use storeId, + // so we need to record the storeId alias for each context key + String storeId = storeAllocation.group(1) + String keyName = storeAllocation.group(2) + storeFieldAliases.put(fieldName(storeId), fieldName(keyName)) + } + } + for (String line : linesOut) { System.out.println(line) + // extract structural info from test application logging if (line.startsWith("___FIELD___")) { String[] parts = line.split(":") parts[2] = storeFieldAliases.get(parts[2]) @@ -97,15 +114,6 @@ class FieldInjectionSmokeTest extends Specification { } else if (line.startsWith("___GENERIC_INTERFACE___")) { String[] parts = line.split(":") foundTypesAndGenericInterfaces.computeIfAbsent(parts[1], { new HashSet<>() }).add(parts[2]) - } else { - Matcher storeAllocation = CONTEXT_STORE_ALLOCATION.matcher(line) - if (storeAllocation.matches()) { - // assertions use context key while internally we use storeId, - // so we need to record the storeId alias for each context key - String storeId = storeAllocation.group(1) - String keyName = storeAllocation.group(2) - storeFieldAliases.put(fieldName(storeId), fieldName(keyName)) - } } } assert testedTypesAndExpectedFields == foundTypesAndFields @@ -113,7 +121,6 @@ class FieldInjectionSmokeTest extends Specification { assert foundTypesAndInterfaces == foundTypesAndGenericInterfaces } - def fieldName(Class klass) { return fieldName(klass.getName()) }