Skip to content

Commit 293429d

Browse files
committed
feat(ci): Fix JUnit test case name uniqueness
1 parent cdee1c8 commit 293429d

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

.circleci/collect_results.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ do
2828
cp "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
2929
# Replace Java Object hashCode by marker in testcase XML nodes to get stable test names
3030
sed -i '/<testcase/ s/@[0-9a-f]\{5,\}/@HASHCODE/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
31+
# Replace random port numbers by marker in testcase XML nodes to get stable test names
32+
sed -i '/<testcase/ s/localhost:[0-9]\{2,5\}/localhost:PORT/g' "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"
3133
if cmp -s "$RESULT_XML_FILE" "$TEST_RESULTS_DIR/$AGGREGATED_FILE_NAME"; then
3234
echo ""
3335
else
34-
echo " (hashCode replaced)"
36+
echo -n " (non-stable test names detected)"
3537
fi
3638
done < <(find "${TEST_RESULT_DIRS[@]}" -name \*.xml -print0)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package datadog.trace.common.writer;
2+
3+
import datadog.trace.bootstrap.instrumentation.api.WriterConstants;
4+
import datadog.trace.core.DDSpan;
5+
import java.io.IOException;
6+
import java.io.ObjectOutputStream;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
import java.util.List;
11+
12+
public class BinaryWriter implements Writer {
13+
private final Path output;
14+
private ObjectOutputStream outputStream;
15+
16+
/**
17+
* Creates a {@link BinaryWriter} from {@link MultiWriter} configuration.
18+
*
19+
* @param configuration The {@link MultiWriter} configuration.
20+
* @return The created writer instance.
21+
*/
22+
public static Writer fromArguments(String configuration) {
23+
if (configuration == null) {
24+
throw new IllegalArgumentException("writer configuration is null");
25+
}
26+
if (configuration.startsWith(WriterConstants.BINARY_WRITER_TYPE + ':')) {
27+
configuration = configuration.substring(WriterConstants.BINARY_WRITER_TYPE.length() + 1);
28+
}
29+
if (configuration.isEmpty()) {
30+
throw new IllegalArgumentException("no output configuration");
31+
}
32+
return new BinaryWriter(Paths.get(configuration));
33+
}
34+
35+
public BinaryWriter(Path output) {
36+
this.output = output;
37+
start();
38+
}
39+
40+
@Override
41+
public void write(List<DDSpan> trace) {
42+
if (this.outputStream != null) {
43+
try {
44+
for (DDSpan span : trace) {
45+
this.outputStream.writeObject(span);
46+
}
47+
} catch (IOException e) {
48+
throw new RuntimeException("Failed to write trace", e);
49+
}
50+
}
51+
}
52+
53+
@Override
54+
public void start() {
55+
checkOutputFolder();
56+
try {
57+
this.outputStream = new ObjectOutputStream(Files.newOutputStream(this.output));
58+
} catch (IOException e) {
59+
throw new RuntimeException(e);
60+
}
61+
}
62+
63+
private void checkOutputFolder() {
64+
if (!Files.exists(this.output.getParent())) {
65+
try {
66+
Files.createFile(this.output.getParent());
67+
} catch (IOException e) {
68+
throw new RuntimeException("Failed to create writer output directory", e);
69+
}
70+
}
71+
}
72+
73+
@Override
74+
public boolean flush() {
75+
if (this.outputStream != null) {
76+
try {
77+
this.outputStream.flush();
78+
return true;
79+
} catch (IOException ignored) {
80+
}
81+
}
82+
return false;
83+
}
84+
85+
@Override
86+
public void close() {
87+
this.outputStream = null;
88+
}
89+
90+
@Override
91+
public void incrementDropCounts(int spanCount) {
92+
// Not supported
93+
}
94+
}

0 commit comments

Comments
 (0)