Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87b99b86 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove dependency on kotlinx.coroutines.test" into main

parents 7d7531cc 02f8b186
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ java_test_host {
    ],
    static_libs: [
        "kotlinx_coroutines",
        "kotlinx_coroutines_test",
    ],
    libs: [
        "junit",
+3 −5
Original line number Diff line number Diff line
@@ -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
@@ -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
+16 −10
Original line number Diff line number Diff line
@@ -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
@@ -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)
    }

@@ -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)