mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Cleanup after each test
This commit is contained in:
parent
d167ff9496
commit
9ef267cb07
8 changed files with 64 additions and 66 deletions
|
@ -38,9 +38,7 @@ class AccountCreationTest : InstrumentedTest {
|
|||
fun createAccountTest() {
|
||||
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))
|
||||
|
||||
commonTestHelper.signout(session)
|
||||
|
||||
session.close()
|
||||
commonTestHelper.signOutAndClose(session)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,14 +48,14 @@ class AccountCreationTest : InstrumentedTest {
|
|||
// Log again to the same account
|
||||
val session2 = commonTestHelper.logIntoAccount(session.myUserId, SessionTestParams(withInitialSync = true))
|
||||
|
||||
session.close()
|
||||
session2.close()
|
||||
commonTestHelper.signOutAndClose(session)
|
||||
commonTestHelper.signOutAndClose(session2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun simpleE2eTest() {
|
||||
val res = cryptoTestHelper.doE2ETestWithAliceInARoom()
|
||||
|
||||
res.close()
|
||||
res.cleanUp(commonTestHelper)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,11 +283,10 @@ class CommonTestHelper(context: Context) {
|
|||
/**
|
||||
* Clear all provided sessions
|
||||
*/
|
||||
fun Iterable<Session>.close() = forEach { it.close() }
|
||||
fun Iterable<Session>.signOutAndClose() = forEach { signOutAndClose(it) }
|
||||
|
||||
fun signout(session: Session) {
|
||||
val lock = CountDownLatch(1)
|
||||
session.signOut(true, TestMatrixCallback(lock))
|
||||
await(lock)
|
||||
fun signOutAndClose(session: Session) {
|
||||
doSync<Unit> { session.signOut(true, it) }
|
||||
session.close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ data class CryptoTestData(val firstSession: Session,
|
|||
val secondSession: Session? = null,
|
||||
val thirdSession: Session? = null) {
|
||||
|
||||
fun close() {
|
||||
firstSession.close()
|
||||
secondSession?.close()
|
||||
secondSession?.close()
|
||||
fun cleanUp(testHelper: CommonTestHelper) {
|
||||
testHelper.signOutAndClose(firstSession)
|
||||
secondSession?.let { testHelper.signOutAndClose(it) }
|
||||
thirdSession?.let { testHelper.signOutAndClose(it) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ class XSigningTest : InstrumentedTest {
|
|||
|
||||
assertTrue("Signing Keys should be trusted", aliceSession.cryptoService().crossSigningService().checkUserTrust(aliceSession.myUserId).isVerified())
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -74,12 +74,8 @@ class XSigningTest : InstrumentedTest {
|
|||
password = TestConstants.PASSWORD
|
||||
)
|
||||
|
||||
val latch = CountDownLatch(2)
|
||||
|
||||
aliceSession.cryptoService().crossSigningService().initializeCrossSigning(aliceAuthParams, TestMatrixCallback(latch))
|
||||
bobSession.cryptoService().crossSigningService().initializeCrossSigning(bobAuthParams, TestMatrixCallback(latch))
|
||||
|
||||
mTestHelper.await(latch)
|
||||
mTestHelper.doSync<Unit> { aliceSession.cryptoService().crossSigningService().initializeCrossSigning(aliceAuthParams, it) }
|
||||
mTestHelper.doSync<Unit> { bobSession.cryptoService().crossSigningService().initializeCrossSigning(bobAuthParams, it) }
|
||||
|
||||
// Check that alice can see bob keys
|
||||
val downloadLatch = CountDownLatch(1)
|
||||
|
@ -96,8 +92,8 @@ class XSigningTest : InstrumentedTest {
|
|||
|
||||
assertFalse("Bob keys from alice pov should not be trusted", bobKeysFromAlicePOV.isTrusted())
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signout(bobSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
mTestHelper.signOutAndClose(bobSession)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -202,8 +198,8 @@ class XSigningTest : InstrumentedTest {
|
|||
val result = aliceSession.cryptoService().crossSigningService().checkDeviceTrust(bobUserId, bobSecondDeviceId, null)
|
||||
assertTrue("Bob second device should be trusted from alice POV", result.isCrossSignedVerified())
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signout(bobSession)
|
||||
mTestHelper.signout(bobSession2)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
mTestHelper.signOutAndClose(bobSession)
|
||||
mTestHelper.signOutAndClose(bobSession2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertNotNull(megolmBackupCreationInfo.recoveryKey)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
bobSession.close()
|
||||
mTestHelper.signOutAndClose(bobSession)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,7 +160,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertTrue(keysBackup.isEnabled)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
bobSession.close()
|
||||
mTestHelper.signOutAndClose(bobSession)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,7 +200,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
KeysBackupState.ReadyToBackUp
|
||||
)
|
||||
)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,7 +239,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals("All keys must have been marked as backed up", nbOfKeys, backedUpKeys)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,7 +282,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertKeysEquals(session.exportKeys(), sessionData)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,7 +308,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
|
||||
checkRestoreSuccess(testData, importRoomKeysResult.totalNumberOfKeys, importRoomKeysResult.successfullyNumberOfImportedKeys)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -359,7 +359,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
// Request is either sent or unsent
|
||||
assertTrue(unsentRequestAfterRestoration == null && sentRequestAfterRestoration == null)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -418,7 +418,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals(2, keysBackupVersionTrust.signatures.size)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -477,7 +477,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals(2, keysBackupVersionTrust.signatures.size)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -516,7 +516,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -577,7 +577,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals(2, keysBackupVersionTrust.signatures.size)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -619,7 +619,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -652,7 +652,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
// onSuccess may not have been called
|
||||
assertNull(importRoomKeysResult)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -707,7 +707,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
|
||||
checkRestoreSuccess(testData, importRoomKeysResult.totalNumberOfKeys, importRoomKeysResult.successfullyNumberOfImportedKeys)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -743,7 +743,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
// onSuccess may not have been called
|
||||
assertNull(importRoomKeysResult)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -771,7 +771,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
|
||||
checkRestoreSuccess(testData, importRoomKeysResult.totalNumberOfKeys, importRoomKeysResult.successfullyNumberOfImportedKeys)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,7 +804,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
// onSuccess may not have been called
|
||||
assertNull(importRoomKeysResult)
|
||||
|
||||
testData.cryptoTestData.close()
|
||||
testData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -844,7 +844,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.credentials.deviceId)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -873,7 +873,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
// - Log Alice on a new device
|
||||
val aliceSession2 = mTestHelper.logIntoAccount(cryptoTestData.firstSession.myUserId, defaultSessionParamsWithInitialSync)
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
|
||||
val keysBackup2 = aliceSession2.cryptoService().keysBackupService()
|
||||
|
||||
|
@ -903,7 +903,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
stateObserver2.stopAndCheckStates(null)
|
||||
aliceSession2.close()
|
||||
mTestHelper.signOutAndClose(aliceSession2)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -970,7 +970,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertFalse(keysBackup.isEnabled)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1073,8 +1073,8 @@ class KeysBackupTest : InstrumentedTest {
|
|||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
stateObserver2.stopAndCheckStates(null)
|
||||
aliceSession2.close()
|
||||
cryptoTestData.close()
|
||||
mTestHelper.signOutAndClose(aliceSession2)
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1103,7 +1103,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertFalse(keysBackup.isEnabled)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/* ==========================================================================================
|
||||
|
@ -1186,7 +1186,12 @@ class KeysBackupTest : InstrumentedTest {
|
|||
private data class KeysBackupScenarioData(val cryptoTestData: CryptoTestData,
|
||||
val aliceKeys: List<OlmInboundGroupSessionWrapper>,
|
||||
val prepareKeysBackupDataResult: PrepareKeysBackupDataResult,
|
||||
val aliceSession2: Session)
|
||||
val aliceSession2: Session) {
|
||||
fun cleanUp(testHelper: CommonTestHelper) {
|
||||
cryptoTestData.cleanUp(testHelper)
|
||||
testHelper.signOutAndClose(aliceSession2)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Common initial condition
|
||||
|
|
|
@ -128,7 +128,7 @@ class QuadSTests : InstrumentedTest {
|
|||
assertNotNull(defaultKeyAccountData?.content)
|
||||
assertEquals("Unexpected default key ${defaultKeyAccountData?.content}", TEST_KEY_ID, defaultKeyAccountData?.content?.get("key"))
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -172,7 +172,7 @@ class QuadSTests : InstrumentedTest {
|
|||
}
|
||||
|
||||
assertEquals("Secret mismatch", clearSecret, decryptedSecret)
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -192,7 +192,7 @@ class QuadSTests : InstrumentedTest {
|
|||
quadS.setDefaultKey(TEST_KEY_ID, it)
|
||||
}
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -239,7 +239,7 @@ class QuadSTests : InstrumentedTest {
|
|||
)
|
||||
}
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -298,7 +298,7 @@ class QuadSTests : InstrumentedTest {
|
|||
)
|
||||
}
|
||||
|
||||
mTestHelper.signout(aliceSession)
|
||||
mTestHelper.signOutAndClose(aliceSession)
|
||||
}
|
||||
|
||||
private fun assertAccountData(session: Session, type: String): UserAccountDataEvent {
|
||||
|
|
|
@ -132,7 +132,7 @@ class SASTest : InstrumentedTest {
|
|||
assertNull(bobVerificationService.getExistingTransaction(aliceSession.myUserId, txID))
|
||||
assertNull(aliceVerificationService.getExistingTransaction(bobSession.myUserId, txID))
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -189,7 +189,7 @@ class SASTest : InstrumentedTest {
|
|||
|
||||
assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod, cancelReason)
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -227,7 +227,7 @@ class SASTest : InstrumentedTest {
|
|||
val cancelReq = canceledToDeviceEvent!!.content.toModel<KeyVerificationCancel>()!!
|
||||
assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code)
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -265,7 +265,7 @@ class SASTest : InstrumentedTest {
|
|||
val cancelReq = canceledToDeviceEvent!!.content.toModel<KeyVerificationCancel>()!!
|
||||
assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code)
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
private fun fakeBobStart(bobSession: Session,
|
||||
|
@ -334,7 +334,7 @@ class SASTest : InstrumentedTest {
|
|||
mTestHelper.await(aliceCreatedLatch)
|
||||
mTestHelper.await(aliceCancelledLatch)
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -393,7 +393,7 @@ class SASTest : InstrumentedTest {
|
|||
assertTrue("all agreed Short Code should be known by alice", startReq!!.shortAuthenticationStrings!!.contains(it))
|
||||
}
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -449,7 +449,7 @@ class SASTest : InstrumentedTest {
|
|||
assertEquals("Should have same SAS", aliceTx.getShortCodeRepresentation(SasMode.DECIMAL),
|
||||
bobTx.getShortCodeRepresentation(SasMode.DECIMAL))
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -514,6 +514,6 @@ class SASTest : InstrumentedTest {
|
|||
|
||||
assertTrue("alice device should be verified from bob point of view", aliceDeviceInfoFromBobPOV!!.isVerified)
|
||||
assertTrue("bob device should be verified from alice point of view", bobDeviceInfoFromAlicePOV!!.isVerified)
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,6 +227,6 @@ class VerificationTest : InstrumentedTest {
|
|||
pr.otherCanScanQrCode() shouldBe expectedResultForBob.otherCanScanQrCode
|
||||
}
|
||||
|
||||
cryptoTestData.close()
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue