Loading tracinglib/core/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,6 @@ java_test_host { ], static_libs: [ "kotlinx_coroutines", "kotlinx_coroutines_test", ], libs: [ "junit", Loading tracinglib/core/host/test/CoroutineTracingTest.kt +3 −5 Original line number Diff line number Diff line Loading @@ -26,13 +26,11 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals Loading Loading @@ -99,7 +97,7 @@ class CoroutineTracingTest : TestBase() { fun nestedUpdateAndRestoreOnSingleThread_unconfinedDispatcher() = runTestWithTraceContext { traceCoroutine("parent-span") { expect(1, "parent-span") launch(UnconfinedTestDispatcher(scheduler = testScheduler)) { launch(Dispatchers.Unconfined) { // While this may appear unusual, it is actually expected behavior: // 1) The parent has an open trace section called "parent-span". // 2) The child launches, it inherits from its parent, and it is resumed Loading tracinglib/core/host/test/TestBase.kt +16 −10 Original line number Diff line number Diff line Loading @@ -21,8 +21,10 @@ import com.android.app.tracing.setAndroidSystemTracingEnabled import com.android.systemui.Flags import com.android.systemui.util.Compile import java.util.concurrent.atomic.AtomicInteger import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.runBlocking import org.junit.After import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertTrue Loading @@ -49,7 +51,19 @@ open class TestBase { ) } protected fun runTestWithTraceContext(block: suspend CoroutineScope.() -> Unit) { runTest(TraceContextElement(), block) } protected fun runTest( context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit, ) { runBlocking(context, block) } protected fun expect(vararg expectedOpenTraceSections: String) { println('s') expect(null, *expectedOpenTraceSections) } Loading Loading @@ -98,11 +112,3 @@ open class TestBase { const val FINAL_EVENT = Int.MIN_VALUE } } /** * Helper util for calling [runTest] with a [TraceContextElement]. This is useful for formatting * purposes. Passing an arg to `runTest {}` directly, as in `fun testStuff() = * runTestWithTraceContext {}` would require more indentations according to our style guide. */ fun runTestWithTraceContext(testBody: suspend TestScope.() -> Unit) = runTest(context = TraceContextElement(), testBody = testBody) Loading
tracinglib/core/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,6 @@ java_test_host { ], static_libs: [ "kotlinx_coroutines", "kotlinx_coroutines_test", ], libs: [ "junit", Loading
tracinglib/core/host/test/CoroutineTracingTest.kt +3 −5 Original line number Diff line number Diff line Loading @@ -26,13 +26,11 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals Loading Loading @@ -99,7 +97,7 @@ class CoroutineTracingTest : TestBase() { fun nestedUpdateAndRestoreOnSingleThread_unconfinedDispatcher() = runTestWithTraceContext { traceCoroutine("parent-span") { expect(1, "parent-span") launch(UnconfinedTestDispatcher(scheduler = testScheduler)) { launch(Dispatchers.Unconfined) { // While this may appear unusual, it is actually expected behavior: // 1) The parent has an open trace section called "parent-span". // 2) The child launches, it inherits from its parent, and it is resumed Loading
tracinglib/core/host/test/TestBase.kt +16 −10 Original line number Diff line number Diff line Loading @@ -21,8 +21,10 @@ import com.android.app.tracing.setAndroidSystemTracingEnabled import com.android.systemui.Flags import com.android.systemui.util.Compile import java.util.concurrent.atomic.AtomicInteger import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.runBlocking import org.junit.After import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertTrue Loading @@ -49,7 +51,19 @@ open class TestBase { ) } protected fun runTestWithTraceContext(block: suspend CoroutineScope.() -> Unit) { runTest(TraceContextElement(), block) } protected fun runTest( context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit, ) { runBlocking(context, block) } protected fun expect(vararg expectedOpenTraceSections: String) { println('s') expect(null, *expectedOpenTraceSections) } Loading Loading @@ -98,11 +112,3 @@ open class TestBase { const val FINAL_EVENT = Int.MIN_VALUE } } /** * Helper util for calling [runTest] with a [TraceContextElement]. This is useful for formatting * purposes. Passing an arg to `runTest {}` directly, as in `fun testStuff() = * runTestWithTraceContext {}` would require more indentations according to our style guide. */ fun runTestWithTraceContext(testBody: suspend TestScope.() -> Unit) = runTest(context = TraceContextElement(), testBody = testBody)