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

Fix flaky test. #2700

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import kotlin.test.assertTrue
import kotlin.test.fail
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flow
import org.junit.After
import org.junit.Before
Expand Down Expand Up @@ -1062,10 +1063,7 @@ class AsyncImageTest {
override suspend fun transform(input: Bitmap, size: Size) = input
}

val flow = flow {
delay(20.milliseconds)
emit(listOf(fakeTransformation, fakeTransformation))
}
val flow = MutableStateFlow(listOf(fakeTransformation))

composeTestRule.setContent {
if (compositionCount.incrementAndGet() > totalCompositions) {
Expand All @@ -1075,13 +1073,17 @@ class AsyncImageTest {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data("https://example.com/image")
.transformations(flow.collectAsState(listOf(fakeTransformation)).value)
.transformations(flow.collectAsState().value)
.build(),
contentDescription = null,
imageLoader = imageLoader,
)
}

waitForRequestComplete(finishedRequests = 1)

flow.value = listOf(fakeTransformation, fakeTransformation)

waitForRequestComplete(finishedRequests = 2)

assertEquals(totalCompositions, compositionCount.get())
Expand Down