2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

Bug 1822394 - Fix intermittent failures in MessagingMiddlewareTest

This commit is contained in:
Christian Sadilek 2023-03-15 14:39:01 -04:00 committed by Ryan VanderMeulen
parent 67d324569b
commit b5b7ad6a7c

View File

@ -9,6 +9,7 @@ import io.mockk.coVerify
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.advanceUntilIdle
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.libstate.ext.waitUntilIdle import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.rule.MainCoroutineRule import mozilla.components.support.test.rule.MainCoroutineRule
import mozilla.components.support.test.rule.runTestOnMain import mozilla.components.support.test.rule.runTestOnMain
@ -60,9 +61,9 @@ class MessagingMiddlewareTest {
coEvery { messagingStorage.getMessages() } returns listOf(message) coEvery { messagingStorage.getMessages() } returns listOf(message)
store.dispatch(Restore) store.dispatch(Restore).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
advanceUntilIdle() coroutineScope.advanceUntilIdle()
assertEquals(listOf(message), store.state.messaging.messages) assertEquals(listOf(message), store.state.messaging.messages)
} }
@ -92,7 +93,7 @@ class MessagingMiddlewareTest {
assertEquals(0, store.state.messaging.messageToShow.size) assertEquals(0, store.state.messaging.messageToShow.size)
store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)) store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
// UpdateMessageToShow to causes messageToShow to append // UpdateMessageToShow to causes messageToShow to append
@ -115,7 +116,7 @@ class MessagingMiddlewareTest {
assertEquals(message, store.state.messaging.messages.first()) assertEquals(message, store.state.messaging.messages.first())
store.dispatch(MessageClicked(message)) store.dispatch(MessageClicked(message)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
assertTrue(store.state.messaging.messages.isEmpty()) assertTrue(store.state.messaging.messages.isEmpty())
@ -136,7 +137,7 @@ class MessagingMiddlewareTest {
MessagingMiddleware(messagingStorage, controller, coroutineScope), MessagingMiddleware(messagingStorage, controller, coroutineScope),
), ),
) )
store.dispatch(MessageDismissed(message)) store.dispatch(MessageDismissed(message)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
assertTrue(store.state.messaging.messages.isEmpty()) assertTrue(store.state.messaging.messages.isEmpty())
@ -160,7 +161,7 @@ class MessagingMiddlewareTest {
), ),
) )
store.dispatch(MessageDismissed(message)) store.dispatch(MessageDismissed(message)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
// removeMessages causes messages size to be 0 // removeMessages causes messages size to be 0
@ -186,7 +187,7 @@ class MessagingMiddlewareTest {
), ),
) )
store.dispatch(MessageClicked(message)) store.dispatch(MessageClicked(message)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
assertTrue(store.state.messaging.messages.isEmpty()) assertTrue(store.state.messaging.messages.isEmpty())
@ -249,7 +250,7 @@ class MessagingMiddlewareTest {
) )
} returns message1 } returns message1
store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)) store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
assertEquals(messageDisplayed1, store.state.messaging.messages[0]) assertEquals(messageDisplayed1, store.state.messaging.messages[0])
@ -281,7 +282,7 @@ class MessagingMiddlewareTest {
) )
} returns message } returns message
store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)) store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
assertEquals(messageDisplayed.metadata.displayCount, store.state.messaging.messages[0].metadata.displayCount) assertEquals(messageDisplayed.metadata.displayCount, store.state.messaging.messages[0].metadata.displayCount)
@ -311,7 +312,7 @@ class MessagingMiddlewareTest {
) )
} returns message } returns message
store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)) store.dispatch(Evaluate(MessageSurfaceId.HOMESCREEN)).joinBlocking()
store.waitUntilIdle() store.waitUntilIdle()
assertEquals(0, store.state.messaging.messages.size) assertEquals(0, store.state.messaging.messages.size)