Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the call to scene.render in tests into the UI thread #910

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ internal abstract class AbstractMainTestClock(
// `currentTime + delayTimeMillis`. See `advanceTimeBy`.
// Therefore we also call `runCurrent` as it's done in TestCoroutineDispatcher
testScheduler.runCurrent()
}

onTimeAdvanced?.invoke(currentTime)
onTimeAdvanced?.invoke(currentTime)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package androidx.compose.ui.test

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameMillis
import androidx.compose.ui.MotionDurationScale
import androidx.compose.ui.test.junit4.createComposeRule
import com.google.common.truth.Truth.assertThat
import kotlin.coroutines.CoroutineContext
import kotlin.test.fail
import kotlinx.coroutines.CoroutineScope
import org.junit.Ignore
import org.junit.Rule
Expand Down Expand Up @@ -126,6 +132,32 @@ class ComposeUiTestTest {
}
}

@Test
fun effectShouldBeCancelledImmediately() {
runComposeUiTest {
var runEffect by mutableStateOf(false)

setContent {
if (runEffect) {
LaunchedEffect(Unit) {
repeat(5) {
withFrameMillis {}
}
runEffect = false
withFrameMillis {
fail("Effect should have stopped running")
}
}
}
}

repeat(2000) {
runEffect = true
waitForIdle()
}
}
}

private class TestCoroutineContextElement : CoroutineContext.Element {
override val key: CoroutineContext.Key<*> get() = Key

Expand Down