Merge pull request #591 from vector-im/feature/bma/noDelayInTests

No delay in tests
This commit is contained in:
Benoit Marty 2023-06-15 15:27:41 +02:00 committed by GitHub
commit 97923af7d8
25 changed files with 169 additions and 180 deletions

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.tests.testutils
import kotlinx.coroutines.delay
/**
* Workaround for https://github.com/cashapp/molecule/issues/249.
* This functions should be removed/deprecated right after we find a proper fix.
*/
suspend inline fun <T> simulateLongTask(lambda: () -> T): T {
delay(1)
return lambda()
}

View file

@ -31,19 +31,18 @@ import kotlinx.coroutines.test.UnconfinedTestDispatcher
* If false, use [StandardTestDispatcher] for all dispatchers.
*/
fun TestScope.testCoroutineDispatchers(
useUnconfinedTestDispatcher: Boolean = true,
useUnconfinedTestDispatcher: Boolean = false,
): CoroutineDispatchers = when (useUnconfinedTestDispatcher) {
false -> CoroutineDispatchers(
io = StandardTestDispatcher(testScheduler),
computation = StandardTestDispatcher(testScheduler),
main = StandardTestDispatcher(testScheduler),
diffUpdateDispatcher = StandardTestDispatcher(testScheduler),
)
true -> CoroutineDispatchers(
io = UnconfinedTestDispatcher(testScheduler),
computation = UnconfinedTestDispatcher(testScheduler),
main = UnconfinedTestDispatcher(testScheduler),
diffUpdateDispatcher = UnconfinedTestDispatcher(testScheduler),
)
false -> CoroutineDispatchers(
io = StandardTestDispatcher(testScheduler),
computation = StandardTestDispatcher(testScheduler),
main = StandardTestDispatcher(testScheduler),
diffUpdateDispatcher = StandardTestDispatcher(testScheduler),
)
}