@@ -62,6 +62,31 @@ public fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null, f
62
62
}
63
63
}
64
64
65
+ /* * Clean the stacktraces from artifacts of BlockHound instrumentation
66
+ *
67
+ * BlockHound works by switching a native call by a class generated with ByteBuddy, which, if the blocking
68
+ * call is allowed in this context, in turn calls the real native call that is now available under a
69
+ * different name.
70
+ *
71
+ * The traces thus undergo the following two changes when the execution is instrumented:
72
+ * - The original native call is replaced with a non-native one with the same FQN, and
73
+ * - An additional native call is placed on top of the stack, with the original name that also has
74
+ * `$$BlockHound$$_` prepended at the last component.
75
+ */
76
+ private fun cleanBlockHoundTraces (frames : List <String >): List <String > {
77
+ var result = mutableListOf<String >()
78
+ val blockHoundSubstr = " \$\$ BlockHound\$\$ _"
79
+ var i = 0
80
+ while (i < frames.size) {
81
+ result.add(frames[i].replace(blockHoundSubstr, " " ))
82
+ if (frames[i].contains(blockHoundSubstr)) {
83
+ i + = 1
84
+ }
85
+ i + = 1
86
+ }
87
+ return result
88
+ }
89
+
65
90
public fun verifyDump (vararg traces : String , ignoredCoroutine : String? = null) {
66
91
val baos = ByteArrayOutputStream ()
67
92
DebugProbes .dumpCoroutines(PrintStream (baos))
@@ -85,7 +110,7 @@ public fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null) {
85
110
expected.withIndex().forEach { (index, trace) ->
86
111
val actualTrace = actual[index].trimStackTrace().sanitizeAddresses()
87
112
val expectedTrace = trace.trimStackTrace().sanitizeAddresses()
88
- val actualLines = actualTrace.split(" \n " )
113
+ val actualLines = cleanBlockHoundTraces( actualTrace.split(" \n " ) )
89
114
val expectedLines = expectedTrace.split(" \n " )
90
115
for (i in expectedLines.indices) {
91
116
assertEquals(expectedLines[i], actualLines[i])
0 commit comments