code review

This commit is contained in:
Valere 2022-05-25 17:47:46 +02:00
parent adb5b4c1b9
commit e1292c03a1
2 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,7 @@ import kotlin.coroutines.resume
class DeactivateAccountTest : InstrumentedTest { class DeactivateAccountTest : InstrumentedTest {
@Test @Test
fun deactivateAccountTest() = runSessionTest(context()) { commonTestHelper -> fun deactivateAccountTest() = runSessionTest(context(), false /* session will be deactivated */) { commonTestHelper ->
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true)) val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))
// Deactivate the account // Deactivate the account

View File

@ -57,25 +57,29 @@ import java.util.concurrent.TimeUnit
class CommonTestHelper private constructor(context: Context) { class CommonTestHelper private constructor(context: Context) {
companion object { companion object {
internal fun runSessionTest(context: Context, block: (CommonTestHelper) -> Unit) { internal fun runSessionTest(context: Context, autoSignoutOnClose: Boolean = true, block: (CommonTestHelper) -> Unit) {
val testHelper = CommonTestHelper(context) val testHelper = CommonTestHelper(context)
return try { return try {
block(testHelper) block(testHelper)
} finally { } finally {
if (autoSignoutOnClose) {
testHelper.cleanUpOpenedSessions() testHelper.cleanUpOpenedSessions()
} }
} }
}
internal fun runCryptoTest(context: Context, block: (CryptoTestHelper, CommonTestHelper) -> Unit) { internal fun runCryptoTest(context: Context, autoSignoutOnClose: Boolean = true, block: (CryptoTestHelper, CommonTestHelper) -> Unit) {
val testHelper = CommonTestHelper(context) val testHelper = CommonTestHelper(context)
val cryptoTestHelper = CryptoTestHelper(testHelper) val cryptoTestHelper = CryptoTestHelper(testHelper)
return try { return try {
block(cryptoTestHelper, testHelper) block(cryptoTestHelper, testHelper)
} finally { } finally {
if (autoSignoutOnClose) {
testHelper.cleanUpOpenedSessions() testHelper.cleanUpOpenedSessions()
} }
} }
} }
}
internal val matrix: TestMatrix internal val matrix: TestMatrix
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main) private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
@ -110,11 +114,7 @@ class CommonTestHelper private constructor(context: Context) {
fun cleanUpOpenedSessions() { fun cleanUpOpenedSessions() {
trackedSessions.forEach { trackedSessions.forEach {
runBlockingTest { runBlockingTest {
try {
it.signOutService().signOut(true) it.signOutService().signOut(true)
} catch (failure: Throwable) {
// Well, as long as you tried.
}
} }
} }
trackedSessions.clear() trackedSessions.clear()