code review
This commit is contained in:
parent
adb5b4c1b9
commit
e1292c03a1
@ -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
|
||||||
|
@ -57,22 +57,26 @@ 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 {
|
||||||
testHelper.cleanUpOpenedSessions()
|
if (autoSignoutOnClose) {
|
||||||
|
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 {
|
||||||
testHelper.cleanUpOpenedSessions()
|
if (autoSignoutOnClose) {
|
||||||
|
testHelper.cleanUpOpenedSessions()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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()
|
||||||
@ -419,8 +419,8 @@ class CommonTestHelper private constructor(context: Context) {
|
|||||||
*/
|
*/
|
||||||
fun await(latch: CountDownLatch, timeout: Long? = TestConstants.timeOutMillis) {
|
fun await(latch: CountDownLatch, timeout: Long? = TestConstants.timeOutMillis) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Timed out after " + timeout + "ms waiting for something to happen. See stacktrace for cause.",
|
"Timed out after " + timeout + "ms waiting for something to happen. See stacktrace for cause.",
|
||||||
latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS)
|
latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user