1 @file:OptIn(ExperimentalCoroutinesApi::class) 2 3 import org.junit.* 4 import kotlinx.coroutines.* 5 import kotlinx.coroutines.debug.* 6 import org.junit.Ignore 7 import org.junit.Test 8 import java.io.* 9 import java.lang.IllegalStateException 10 import kotlin.test.* 11 12 class DynamicAttachDebugJpmsTest { 13 14 /** 15 * This test is disabled because: 16 * Dynamic Attach with JPMS is not yet supported. 17 * 18 * Here is the state of experiments: 19 * When launching this test with additional workarounds like 20 * ``` 21 * jvmArgs("--add-exports=kotlinx.coroutines.debug/kotlinx.coroutines.repackaged.net.bytebuddy=com.sun.jna") 22 * jvmArgs("--add-exports=kotlinx.coroutines.debug/kotlinx.coroutines.repackaged.net.bytebuddy.agent=com.sun.jna") 23 *``` 24 * 25 * Then we see issues like 26 * 27 * ``` 28 * Caused by: java.lang.IllegalStateException: The Byte Buddy agent is not loaded or this method is not called via the system class loader 29 * at kotlinx.coroutines.debug/kotlinx.coroutines.repackaged.net.bytebuddy.agent.Installer.getInstrumentation(Installer.java:61) 30 * ... 54 more 31 * ``` 32 */ 33 @Ignore("shaded byte-buddy does not work with JPMS") 34 @Test testAgentDumpsCoroutinesnull35 fun testAgentDumpsCoroutines() = 36 DebugProbes.withDebugProbes { 37 runBlocking { 38 val baos = ByteArrayOutputStream() 39 DebugProbes.dumpCoroutines(PrintStream(baos)) 40 // if the agent works, then dumps should contain something, 41 // at least the fact that this test is running. 42 Assert.assertTrue(baos.toString().contains("testAgentDumpsCoroutines")) 43 } 44 } 45 46 @Test testAgentIsNotInstallednull47 fun testAgentIsNotInstalled() { 48 assertEquals(false, DebugProbes.isInstalled) 49 assertFailsWith<IllegalStateException> { 50 DebugProbes.dumpCoroutines(PrintStream(ByteArrayOutputStream())) 51 } 52 } 53 54 } 55