Skip to content

Commit

Permalink
Fix warnings in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Jul 10, 2024
1 parent cb4af72 commit fc29236
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -58,6 +57,7 @@ import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlin.time.Duration.Companion.milliseconds

/**
* This class exposes methods to be used in common cases
Expand All @@ -67,10 +67,9 @@ class CommonTestHelper internal constructor(context: Context, val cryptoConfig:

companion object {

@OptIn(ExperimentalCoroutinesApi::class)
internal fun runSessionTest(context: Context, cryptoConfig: MXCryptoConfig? = null, autoSignoutOnClose: Boolean = true, block: suspend CoroutineScope.(CommonTestHelper) -> Unit) {
val testHelper = CommonTestHelper(context, cryptoConfig)
return runTest(dispatchTimeoutMs = TestConstants.timeOutMillis) {
return runTest(timeout = TestConstants.timeOutMillis.milliseconds) {
try {
withContext(Dispatchers.Default) {
block(testHelper)
Expand All @@ -83,11 +82,10 @@ class CommonTestHelper internal constructor(context: Context, val cryptoConfig:
}
}

@OptIn(ExperimentalCoroutinesApi::class)
internal fun runCryptoTest(context: Context, cryptoConfig: MXCryptoConfig? = null, autoSignoutOnClose: Boolean = true, block: suspend CoroutineScope.(CryptoTestHelper, CommonTestHelper) -> Unit) {
val testHelper = CommonTestHelper(context, cryptoConfig)
val cryptoTestHelper = CryptoTestHelper(testHelper)
return runTest(dispatchTimeoutMs = TestConstants.timeOutMillis) {
return runTest(timeout = TestConstants.timeOutMillis.milliseconds) {
try {
withContext(Dispatchers.Default) {
block(cryptoTestHelper, testHelper)
Expand All @@ -100,11 +98,10 @@ class CommonTestHelper internal constructor(context: Context, val cryptoConfig:
}
}

@OptIn(ExperimentalCoroutinesApi::class)
internal fun runLongCryptoTest(context: Context, cryptoConfig: MXCryptoConfig? = null, autoSignoutOnClose: Boolean = true, block: suspend CoroutineScope.(CryptoTestHelper, CommonTestHelper) -> Unit) {
val testHelper = CommonTestHelper(context, cryptoConfig)
val cryptoTestHelper = CryptoTestHelper(testHelper)
return runTest(dispatchTimeoutMs = TestConstants.timeOutMillis * 4) {
return runTest(timeout = (TestConstants.timeOutMillis * 4).milliseconds) {
try {
withContext(Dispatchers.Default) {
block(cryptoTestHelper, testHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ suspend fun <T> LiveData<T>.first(timeout: Long = TestConstants.timeOutMillis, p
withContext(Dispatchers.Main) {
suspendCancellableCoroutine { continuation ->
val observer = object : Observer<T> {
override fun onChanged(data: T) {
if (predicate(data)) {
override fun onChanged(value: T) {
if (predicate(value)) {
removeObserver(this)
continuation.resume(data)
continuation.resume(value)
}
}
}
Expand Down

0 comments on commit fc29236

Please sign in to comment.