Cleanup after each test

This commit is contained in:
Benoit Marty 2020-02-21 18:36:13 +01:00
parent d167ff9496
commit 9ef267cb07
8 changed files with 64 additions and 66 deletions

View file

@ -38,9 +38,7 @@ class AccountCreationTest : InstrumentedTest {
fun createAccountTest() { fun createAccountTest() {
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true)) val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))
commonTestHelper.signout(session) commonTestHelper.signOutAndClose(session)
session.close()
} }
@Test @Test
@ -50,14 +48,14 @@ class AccountCreationTest : InstrumentedTest {
// Log again to the same account // Log again to the same account
val session2 = commonTestHelper.logIntoAccount(session.myUserId, SessionTestParams(withInitialSync = true)) val session2 = commonTestHelper.logIntoAccount(session.myUserId, SessionTestParams(withInitialSync = true))
session.close() commonTestHelper.signOutAndClose(session)
session2.close() commonTestHelper.signOutAndClose(session2)
} }
@Test @Test
fun simpleE2eTest() { fun simpleE2eTest() {
val res = cryptoTestHelper.doE2ETestWithAliceInARoom() val res = cryptoTestHelper.doE2ETestWithAliceInARoom()
res.close() res.cleanUp(commonTestHelper)
} }
} }

View file

@ -283,11 +283,10 @@ class CommonTestHelper(context: Context) {
/** /**
* Clear all provided sessions * Clear all provided sessions
*/ */
fun Iterable<Session>.close() = forEach { it.close() } fun Iterable<Session>.signOutAndClose() = forEach { signOutAndClose(it) }
fun signout(session: Session) { fun signOutAndClose(session: Session) {
val lock = CountDownLatch(1) doSync<Unit> { session.signOut(true, it) }
session.signOut(true, TestMatrixCallback(lock)) session.close()
await(lock)
} }
} }

View file

@ -23,9 +23,9 @@ data class CryptoTestData(val firstSession: Session,
val secondSession: Session? = null, val secondSession: Session? = null,
val thirdSession: Session? = null) { val thirdSession: Session? = null) {
fun close() { fun cleanUp(testHelper: CommonTestHelper) {
firstSession.close() testHelper.signOutAndClose(firstSession)
secondSession?.close() secondSession?.let { testHelper.signOutAndClose(it) }
secondSession?.close() thirdSession?.let { testHelper.signOutAndClose(it) }
} }
} }

View file

@ -55,7 +55,7 @@ class XSigningTest : InstrumentedTest {
assertTrue("Signing Keys should be trusted", aliceSession.cryptoService().crossSigningService().checkUserTrust(aliceSession.myUserId).isVerified()) assertTrue("Signing Keys should be trusted", aliceSession.cryptoService().crossSigningService().checkUserTrust(aliceSession.myUserId).isVerified())
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
} }
@Test @Test
@ -74,12 +74,8 @@ class XSigningTest : InstrumentedTest {
password = TestConstants.PASSWORD password = TestConstants.PASSWORD
) )
val latch = CountDownLatch(2) mTestHelper.doSync<Unit> { aliceSession.cryptoService().crossSigningService().initializeCrossSigning(aliceAuthParams, it) }
mTestHelper.doSync<Unit> { bobSession.cryptoService().crossSigningService().initializeCrossSigning(bobAuthParams, it) }
aliceSession.cryptoService().crossSigningService().initializeCrossSigning(aliceAuthParams, TestMatrixCallback(latch))
bobSession.cryptoService().crossSigningService().initializeCrossSigning(bobAuthParams, TestMatrixCallback(latch))
mTestHelper.await(latch)
// Check that alice can see bob keys // Check that alice can see bob keys
val downloadLatch = CountDownLatch(1) val downloadLatch = CountDownLatch(1)
@ -96,8 +92,8 @@ class XSigningTest : InstrumentedTest {
assertFalse("Bob keys from alice pov should not be trusted", bobKeysFromAlicePOV.isTrusted()) assertFalse("Bob keys from alice pov should not be trusted", bobKeysFromAlicePOV.isTrusted())
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
mTestHelper.signout(bobSession) mTestHelper.signOutAndClose(bobSession)
} }
@Test @Test
@ -202,8 +198,8 @@ class XSigningTest : InstrumentedTest {
val result = aliceSession.cryptoService().crossSigningService().checkDeviceTrust(bobUserId, bobSecondDeviceId, null) val result = aliceSession.cryptoService().crossSigningService().checkDeviceTrust(bobUserId, bobSecondDeviceId, null)
assertTrue("Bob second device should be trusted from alice POV", result.isCrossSignedVerified()) assertTrue("Bob second device should be trusted from alice POV", result.isCrossSignedVerified())
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
mTestHelper.signout(bobSession) mTestHelper.signOutAndClose(bobSession)
mTestHelper.signout(bobSession2) mTestHelper.signOutAndClose(bobSession2)
} }
} }

View file

@ -129,7 +129,7 @@ class KeysBackupTest : InstrumentedTest {
assertNotNull(megolmBackupCreationInfo.recoveryKey) assertNotNull(megolmBackupCreationInfo.recoveryKey)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
bobSession.close() mTestHelper.signOutAndClose(bobSession)
} }
/** /**
@ -160,7 +160,7 @@ class KeysBackupTest : InstrumentedTest {
assertTrue(keysBackup.isEnabled) assertTrue(keysBackup.isEnabled)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
bobSession.close() mTestHelper.signOutAndClose(bobSession)
} }
/** /**
@ -200,7 +200,7 @@ class KeysBackupTest : InstrumentedTest {
KeysBackupState.ReadyToBackUp 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) assertEquals("All keys must have been marked as backed up", nbOfKeys, backedUpKeys)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
/** /**
@ -282,7 +282,7 @@ class KeysBackupTest : InstrumentedTest {
assertKeysEquals(session.exportKeys(), sessionData) assertKeysEquals(session.exportKeys(), sessionData)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
/** /**
@ -308,7 +308,7 @@ class KeysBackupTest : InstrumentedTest {
checkRestoreSuccess(testData, importRoomKeysResult.totalNumberOfKeys, importRoomKeysResult.successfullyNumberOfImportedKeys) 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 // Request is either sent or unsent
assertTrue(unsentRequestAfterRestoration == null && sentRequestAfterRestoration == null) assertTrue(unsentRequestAfterRestoration == null && sentRequestAfterRestoration == null)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -418,7 +418,7 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(2, keysBackupVersionTrust.signatures.size) assertEquals(2, keysBackupVersionTrust.signatures.size)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -477,7 +477,7 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(2, keysBackupVersionTrust.signatures.size) assertEquals(2, keysBackupVersionTrust.signatures.size)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -516,7 +516,7 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state) assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -577,7 +577,7 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(2, keysBackupVersionTrust.signatures.size) assertEquals(2, keysBackupVersionTrust.signatures.size)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -619,7 +619,7 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state) assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -652,7 +652,7 @@ class KeysBackupTest : InstrumentedTest {
// onSuccess may not have been called // onSuccess may not have been called
assertNull(importRoomKeysResult) assertNull(importRoomKeysResult)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -707,7 +707,7 @@ class KeysBackupTest : InstrumentedTest {
checkRestoreSuccess(testData, importRoomKeysResult.totalNumberOfKeys, importRoomKeysResult.successfullyNumberOfImportedKeys) 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 // onSuccess may not have been called
assertNull(importRoomKeysResult) assertNull(importRoomKeysResult)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -771,7 +771,7 @@ class KeysBackupTest : InstrumentedTest {
checkRestoreSuccess(testData, importRoomKeysResult.totalNumberOfKeys, importRoomKeysResult.successfullyNumberOfImportedKeys) 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 // onSuccess may not have been called
assertNull(importRoomKeysResult) assertNull(importRoomKeysResult)
testData.cryptoTestData.close() testData.cleanUp(mTestHelper)
} }
/** /**
@ -844,7 +844,7 @@ class KeysBackupTest : InstrumentedTest {
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.credentials.deviceId) assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.credentials.deviceId)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
/** /**
@ -873,7 +873,7 @@ class KeysBackupTest : InstrumentedTest {
// - Log Alice on a new device // - Log Alice on a new device
val aliceSession2 = mTestHelper.logIntoAccount(cryptoTestData.firstSession.myUserId, defaultSessionParamsWithInitialSync) val aliceSession2 = mTestHelper.logIntoAccount(cryptoTestData.firstSession.myUserId, defaultSessionParamsWithInitialSync)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
val keysBackup2 = aliceSession2.cryptoService().keysBackupService() val keysBackup2 = aliceSession2.cryptoService().keysBackupService()
@ -903,7 +903,7 @@ class KeysBackupTest : InstrumentedTest {
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
stateObserver2.stopAndCheckStates(null) stateObserver2.stopAndCheckStates(null)
aliceSession2.close() mTestHelper.signOutAndClose(aliceSession2)
} }
/** /**
@ -970,7 +970,7 @@ class KeysBackupTest : InstrumentedTest {
assertFalse(keysBackup.isEnabled) assertFalse(keysBackup.isEnabled)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
/** /**
@ -1073,8 +1073,8 @@ class KeysBackupTest : InstrumentedTest {
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
stateObserver2.stopAndCheckStates(null) stateObserver2.stopAndCheckStates(null)
aliceSession2.close() mTestHelper.signOutAndClose(aliceSession2)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
/** /**
@ -1103,7 +1103,7 @@ class KeysBackupTest : InstrumentedTest {
assertFalse(keysBackup.isEnabled) assertFalse(keysBackup.isEnabled)
stateObserver.stopAndCheckStates(null) stateObserver.stopAndCheckStates(null)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
/* ========================================================================================== /* ==========================================================================================
@ -1186,7 +1186,12 @@ class KeysBackupTest : InstrumentedTest {
private data class KeysBackupScenarioData(val cryptoTestData: CryptoTestData, private data class KeysBackupScenarioData(val cryptoTestData: CryptoTestData,
val aliceKeys: List<OlmInboundGroupSessionWrapper>, val aliceKeys: List<OlmInboundGroupSessionWrapper>,
val prepareKeysBackupDataResult: PrepareKeysBackupDataResult, val prepareKeysBackupDataResult: PrepareKeysBackupDataResult,
val aliceSession2: Session) val aliceSession2: Session) {
fun cleanUp(testHelper: CommonTestHelper) {
cryptoTestData.cleanUp(testHelper)
testHelper.signOutAndClose(aliceSession2)
}
}
/** /**
* Common initial condition * Common initial condition

View file

@ -128,7 +128,7 @@ class QuadSTests : InstrumentedTest {
assertNotNull(defaultKeyAccountData?.content) assertNotNull(defaultKeyAccountData?.content)
assertEquals("Unexpected default key ${defaultKeyAccountData?.content}", TEST_KEY_ID, defaultKeyAccountData?.content?.get("key")) assertEquals("Unexpected default key ${defaultKeyAccountData?.content}", TEST_KEY_ID, defaultKeyAccountData?.content?.get("key"))
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
} }
@Test @Test
@ -172,7 +172,7 @@ class QuadSTests : InstrumentedTest {
} }
assertEquals("Secret mismatch", clearSecret, decryptedSecret) assertEquals("Secret mismatch", clearSecret, decryptedSecret)
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
} }
@Test @Test
@ -192,7 +192,7 @@ class QuadSTests : InstrumentedTest {
quadS.setDefaultKey(TEST_KEY_ID, it) quadS.setDefaultKey(TEST_KEY_ID, it)
} }
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
} }
@Test @Test
@ -239,7 +239,7 @@ class QuadSTests : InstrumentedTest {
) )
} }
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
} }
@Test @Test
@ -298,7 +298,7 @@ class QuadSTests : InstrumentedTest {
) )
} }
mTestHelper.signout(aliceSession) mTestHelper.signOutAndClose(aliceSession)
} }
private fun assertAccountData(session: Session, type: String): UserAccountDataEvent { private fun assertAccountData(session: Session, type: String): UserAccountDataEvent {

View file

@ -132,7 +132,7 @@ class SASTest : InstrumentedTest {
assertNull(bobVerificationService.getExistingTransaction(aliceSession.myUserId, txID)) assertNull(bobVerificationService.getExistingTransaction(aliceSession.myUserId, txID))
assertNull(aliceVerificationService.getExistingTransaction(bobSession.myUserId, txID)) assertNull(aliceVerificationService.getExistingTransaction(bobSession.myUserId, txID))
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
@Test @Test
@ -189,7 +189,7 @@ class SASTest : InstrumentedTest {
assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod, cancelReason) assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod, cancelReason)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
@Test @Test
@ -227,7 +227,7 @@ class SASTest : InstrumentedTest {
val cancelReq = canceledToDeviceEvent!!.content.toModel<KeyVerificationCancel>()!! val cancelReq = canceledToDeviceEvent!!.content.toModel<KeyVerificationCancel>()!!
assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code) assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
@Test @Test
@ -265,7 +265,7 @@ class SASTest : InstrumentedTest {
val cancelReq = canceledToDeviceEvent!!.content.toModel<KeyVerificationCancel>()!! val cancelReq = canceledToDeviceEvent!!.content.toModel<KeyVerificationCancel>()!!
assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code) assertEquals("Request should be cancelled with m.unknown_method", CancelCode.UnknownMethod.value, cancelReq.code)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
private fun fakeBobStart(bobSession: Session, private fun fakeBobStart(bobSession: Session,
@ -334,7 +334,7 @@ class SASTest : InstrumentedTest {
mTestHelper.await(aliceCreatedLatch) mTestHelper.await(aliceCreatedLatch)
mTestHelper.await(aliceCancelledLatch) 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)) assertTrue("all agreed Short Code should be known by alice", startReq!!.shortAuthenticationStrings!!.contains(it))
} }
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
@Test @Test
@ -449,7 +449,7 @@ class SASTest : InstrumentedTest {
assertEquals("Should have same SAS", aliceTx.getShortCodeRepresentation(SasMode.DECIMAL), assertEquals("Should have same SAS", aliceTx.getShortCodeRepresentation(SasMode.DECIMAL),
bobTx.getShortCodeRepresentation(SasMode.DECIMAL)) bobTx.getShortCodeRepresentation(SasMode.DECIMAL))
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
@Test @Test
@ -514,6 +514,6 @@ class SASTest : InstrumentedTest {
assertTrue("alice device should be verified from bob point of view", aliceDeviceInfoFromBobPOV!!.isVerified) 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) assertTrue("bob device should be verified from alice point of view", bobDeviceInfoFromAlicePOV!!.isVerified)
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
} }

View file

@ -227,6 +227,6 @@ class VerificationTest : InstrumentedTest {
pr.otherCanScanQrCode() shouldBe expectedResultForBob.otherCanScanQrCode pr.otherCanScanQrCode() shouldBe expectedResultForBob.otherCanScanQrCode
} }
cryptoTestData.close() cryptoTestData.cleanUp(mTestHelper)
} }
} }