Merge "Revert "Update OverviewCommandHelper to use Executors.MAIN to reduce the percentage of missed frames"" into main
This commit is contained in:
+5
-20
@@ -41,6 +41,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.doAnswer
|
||||
import org.mockito.Mockito.spy
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.mock
|
||||
|
||||
@@ -55,12 +56,10 @@ class OverviewCommandHelperTest {
|
||||
private val testScope = TestScope(dispatcher)
|
||||
|
||||
private var pendingCallbacksWithDelays = mutableListOf<Long>()
|
||||
private lateinit var pendingCommandsToExecute: MutableList<Runnable>
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Before
|
||||
fun setup() {
|
||||
pendingCommandsToExecute = mutableListOf()
|
||||
setFlagsRule.setFlags(true, Flags.FLAG_ENABLE_OVERVIEW_COMMAND_HELPER_TIMEOUT)
|
||||
|
||||
sut =
|
||||
@@ -69,8 +68,7 @@ class OverviewCommandHelperTest {
|
||||
touchInteractionService = mock(),
|
||||
overviewComponentObserver = mock(),
|
||||
taskAnimationManager = mock(),
|
||||
dispatcherProvider = TestDispatcherProvider(dispatcher),
|
||||
uiExecutor = { runnable -> pendingCommandsToExecute += runnable },
|
||||
dispatcherProvider = TestDispatcherProvider(dispatcher)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -96,21 +94,12 @@ class OverviewCommandHelperTest {
|
||||
pendingCallbacksWithDelays.add(delayInMillis)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function runs all the pending commands from the Executor for testing purposes. Replacing
|
||||
* the uiExecutor allows the test to execute the command queue manually, making it possible to
|
||||
* assert each state of the commands in the queue individually.
|
||||
*/
|
||||
private fun executePendingCommands() = pendingCommandsToExecute.forEach { it.run() }
|
||||
|
||||
@Test
|
||||
fun whenFirstCommandIsAdded_executeCommandImmediately() =
|
||||
testScope.runTest {
|
||||
// Add command to queue
|
||||
val commandInfo: CommandInfo = sut.addCommand(CommandType.HOME)!!
|
||||
assertThat(commandInfo.status).isEqualTo(CommandStatus.IDLE)
|
||||
executePendingCommands()
|
||||
assertThat(commandInfo.status).isEqualTo(CommandStatus.PROCESSING)
|
||||
runCurrent()
|
||||
assertThat(commandInfo.status).isEqualTo(CommandStatus.COMPLETED)
|
||||
}
|
||||
@@ -125,7 +114,7 @@ class OverviewCommandHelperTest {
|
||||
val commandInfo: CommandInfo = sut.addCommand(commandType)!!
|
||||
assertThat(commandInfo.status).isEqualTo(CommandStatus.IDLE)
|
||||
|
||||
executePendingCommands()
|
||||
runCurrent()
|
||||
assertThat(commandInfo.status).isEqualTo(CommandStatus.PROCESSING)
|
||||
|
||||
advanceTimeBy(200L)
|
||||
@@ -146,14 +135,12 @@ class OverviewCommandHelperTest {
|
||||
val commandInfo2: CommandInfo = sut.addCommand(commandType2)!!
|
||||
assertThat(commandInfo2.status).isEqualTo(CommandStatus.IDLE)
|
||||
|
||||
executePendingCommands()
|
||||
runCurrent()
|
||||
assertThat(commandInfo1.status).isEqualTo(CommandStatus.PROCESSING)
|
||||
assertThat(commandInfo2.status).isEqualTo(CommandStatus.IDLE)
|
||||
|
||||
advanceTimeBy(101L)
|
||||
assertThat(commandInfo1.status).isEqualTo(CommandStatus.COMPLETED)
|
||||
|
||||
executePendingCommands()
|
||||
assertThat(commandInfo2.status).isEqualTo(CommandStatus.PROCESSING)
|
||||
|
||||
advanceTimeBy(101L)
|
||||
@@ -174,14 +161,12 @@ class OverviewCommandHelperTest {
|
||||
val commandInfo2: CommandInfo = sut.addCommand(commandType2)!!
|
||||
assertThat(commandInfo2.status).isEqualTo(CommandStatus.IDLE)
|
||||
|
||||
executePendingCommands()
|
||||
runCurrent()
|
||||
assertThat(commandInfo1.status).isEqualTo(CommandStatus.PROCESSING)
|
||||
assertThat(commandInfo2.status).isEqualTo(CommandStatus.IDLE)
|
||||
|
||||
advanceTimeBy(QUEUE_TIMEOUT)
|
||||
assertThat(commandInfo1.status).isEqualTo(CommandStatus.CANCELED)
|
||||
|
||||
executePendingCommands()
|
||||
assertThat(commandInfo2.status).isEqualTo(CommandStatus.PROCESSING)
|
||||
|
||||
advanceTimeBy(101)
|
||||
|
||||
Reference in New Issue
Block a user