Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flakiness from field-injection smoke test #8214

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<String> lines = Files.readAllLines(testOutput)
List<String> linesOut = Files.readAllLines(testOut)
List<String> linesErr = Files.readAllLines(testErr)
Map<String, Set<String>> foundTypesAndFields = new HashMap<>()
Map<String, List<String>> foundTypesAndInterfaces = new HashMap<>()
Map<String, List<String>> foundTypesAndGenericInterfaces = new HashMap<>()
Map<String, String> 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])
Expand All @@ -97,23 +114,13 @@ 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
// check same list of names for interfaces and generic interfaces
assert foundTypesAndInterfaces == foundTypesAndGenericInterfaces
}


def fieldName(Class<?> klass) {
return fieldName(klass.getName())
}
Expand Down
Loading