1
0
mirror of https://github.com/vector-im/riotX-android synced 2025-10-07 08:42:40 +02:00

Compare commits

...

1 Commits

Author SHA1 Message Date
Michael Kaye
14e7c71b26 Initial work to ensure that all AssertionFailures have a message.
There's more to fix up...
2022-05-05 14:36:28 +01:00
3 changed files with 24 additions and 18 deletions

View File

@@ -111,7 +111,7 @@ class CommonTestHelper(context: Context) {
} }
syncLiveData.observeForever(syncObserver) syncLiveData.observeForever(syncObserver)
} }
await(lock, timeout) await("Timeout waiting to sync session", lock, timeout)
} }
/** /**
@@ -120,7 +120,7 @@ class CommonTestHelper(context: Context) {
* @param session the session to sync * @param session the session to sync
*/ */
fun clearCacheAndSync(session: Session, timeout: Long = TestConstants.timeOutMillis) { fun clearCacheAndSync(session: Session, timeout: Long = TestConstants.timeOutMillis) {
waitWithLatch(timeout) { latch -> waitWithLatch("Timeout waiting to clear cache and sync", timeout) { latch ->
session.clearCache() session.clearCache()
val syncLiveData = session.getSyncStateLive() val syncLiveData = session.getSyncStateLive()
val syncObserver = object : Observer<SyncState> { val syncObserver = object : Observer<SyncState> {
@@ -172,7 +172,7 @@ class CommonTestHelper(context: Context) {
room.sendService().sendTextMessage(formattedMessage) room.sendService().sendTextMessage(formattedMessage)
} }
} }
waitWithLatch(timeout) { latch -> waitWithLatch("Timeout waiting for batch of messages to send", timeout) { latch ->
val timelineListener = object : Timeline.Listener { val timelineListener = object : Timeline.Listener {
override fun onTimelineUpdated(snapshot: List<TimelineEvent>) { override fun onTimelineUpdated(snapshot: List<TimelineEvent>) {
@@ -374,8 +374,8 @@ class CommonTestHelper(context: Context) {
* @param latch * @param latch
* @throws InterruptedException * @throws InterruptedException
*/ */
fun await(latch: CountDownLatch, timeout: Long? = TestConstants.timeOutMillis) { fun await(message: String, latch: CountDownLatch, timeout: Long? = TestConstants.timeOutMillis) {
assertTrue(latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS)) assertTrue(message, latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
} }
suspend fun retryPeriodicallyWithLatch(latch: CountDownLatch, condition: (() -> Boolean)) { suspend fun retryPeriodicallyWithLatch(latch: CountDownLatch, condition: (() -> Boolean)) {
@@ -388,12 +388,12 @@ class CommonTestHelper(context: Context) {
} }
} }
fun waitWithLatch(timeout: Long? = TestConstants.timeOutMillis, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend (CountDownLatch) -> Unit) { fun waitWithLatch(message: String, timeout: Long? = TestConstants.timeOutMillis, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend (CountDownLatch) -> Unit) {
val latch = CountDownLatch(1) val latch = CountDownLatch(1)
coroutineScope.launch(dispatcher) { coroutineScope.launch(dispatcher) {
block(latch) block(latch)
} }
await(latch, timeout) await(message, latch, timeout)
} }
fun <T> runBlockingTest(timeout: Long = TestConstants.timeOutMillis, block: suspend () -> T): T { fun <T> runBlockingTest(timeout: Long = TestConstants.timeOutMillis, block: suspend () -> T): T {
@@ -418,7 +418,7 @@ class CommonTestHelper(context: Context) {
block.invoke(callback) block.invoke(callback)
await(lock, timeout) await("Timeout waiting for sync", lock, timeout)
assertNotNull(result) assertNotNull(result)
return result!! return result!!

View File

@@ -68,7 +68,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
aliceSession.roomService().createRoom(CreateRoomParams().apply { name = "MyRoom" }) aliceSession.roomService().createRoom(CreateRoomParams().apply { name = "MyRoom" })
} }
if (encryptedRoom) { if (encryptedRoom) {
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch("Wait for encryption to be enabled in room") { latch ->
val room = aliceSession.getRoom(roomId)!! val room = aliceSession.getRoom(roomId)!!
room.roomCryptoService().enableEncryption() room.roomCryptoService().enableEncryption()
val roomSummaryLive = room.getRoomSummaryLive() val roomSummaryLive = room.getRoomSummaryLive()
@@ -98,7 +98,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
val bobSession = testHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams) val bobSession = testHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams)
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch("Timeout waiting for bob to see invite to room") { latch ->
val bobRoomSummariesLive = bobSession.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val bobRoomSummariesLive = bobSession.roomService().getRoomSummariesLive(roomSummaryQueryParams { })
val newRoomObserver = object : Observer<List<RoomSummary>> { val newRoomObserver = object : Observer<List<RoomSummary>> {
override fun onChanged(t: List<RoomSummary>?) { override fun onChanged(t: List<RoomSummary>?) {
@@ -112,7 +112,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
aliceRoom.membershipService().invite(bobSession.myUserId) aliceRoom.membershipService().invite(bobSession.myUserId)
} }
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch("Timeout waiting for bob to join room") { latch ->
val bobRoomSummariesLive = bobSession.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val bobRoomSummariesLive = bobSession.roomService().getRoomSummariesLive(roomSummaryQueryParams { })
val roomJoinedObserver = object : Observer<List<RoomSummary>> { val roomJoinedObserver = object : Observer<List<RoomSummary>> {
override fun onChanged(t: List<RoomSummary>?) { override fun onChanged(t: List<RoomSummary>?) {
@@ -243,7 +243,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
fun createDM(alice: Session, bob: Session): String { fun createDM(alice: Session, bob: Session): String {
var roomId: String = "" var roomId: String = ""
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch("Timeout waiting for bob to see DM from alice") { latch ->
roomId = alice.roomService().createDirectRoom(bob.myUserId) roomId = alice.roomService().createDirectRoom(bob.myUserId)
val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { })
val newRoomObserver = object : Observer<List<RoomSummary>> { val newRoomObserver = object : Observer<List<RoomSummary>> {
@@ -257,7 +257,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
bobRoomSummariesLive.observeForever(newRoomObserver) bobRoomSummariesLive.observeForever(newRoomObserver)
} }
testHelper.waitWithLatch { latch -> testHelper.waitWithLatch("Timeout waiting for bob to join DM wih alice") { latch ->
val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { }) val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { })
val newRoomObserver = object : Observer<List<RoomSummary>> { val newRoomObserver = object : Observer<List<RoomSummary>> {
override fun onChanged(t: List<RoomSummary>?) { override fun onChanged(t: List<RoomSummary>?) {
@@ -315,7 +315,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
var bobPovTx: IncomingSasVerificationTransaction? = null var bobPovTx: IncomingSasVerificationTransaction? = null
// wait for alice to get the ready // wait for alice to get the ready
testHelper.waitWithLatch { testHelper.waitWithLatch("Timeout waiting for bob to see verification started") {
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(it) {
bobPovTx = bobVerificationService.getExistingTransaction(alice.myUserId, requestID) as? IncomingSasVerificationTransaction bobPovTx = bobVerificationService.getExistingTransaction(alice.myUserId, requestID) as? IncomingSasVerificationTransaction
Log.v("TEST", "== bobPovTx is ${alicePovTx?.uxState}") Log.v("TEST", "== bobPovTx is ${alicePovTx?.uxState}")
@@ -328,7 +328,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
} }
} }
testHelper.waitWithLatch { testHelper.waitWithLatch("Timeout waiting for alice to be ShortCodeReady") {
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(it) {
alicePovTx = aliceVerificationService.getExistingTransaction(bob.myUserId, requestID) as? OutgoingSasVerificationTransaction alicePovTx = aliceVerificationService.getExistingTransaction(bob.myUserId, requestID) as? OutgoingSasVerificationTransaction
Log.v("TEST", "== alicePovTx is ${alicePovTx?.uxState}") Log.v("TEST", "== alicePovTx is ${alicePovTx?.uxState}")
@@ -336,7 +336,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
} }
} }
// wait for alice to get the ready // wait for alice to get the ready
testHelper.waitWithLatch { testHelper.waitWithLatch("Timeout waiting for bob to be ShortCodeReady") {
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(it) {
bobPovTx = bobVerificationService.getExistingTransaction(alice.myUserId, requestID) as? IncomingSasVerificationTransaction bobPovTx = bobVerificationService.getExistingTransaction(alice.myUserId, requestID) as? IncomingSasVerificationTransaction
Log.v("TEST", "== bobPovTx is ${alicePovTx?.uxState}") Log.v("TEST", "== bobPovTx is ${alicePovTx?.uxState}")
@@ -352,13 +352,14 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
bobPovTx!!.userHasVerifiedShortCode() bobPovTx!!.userHasVerifiedShortCode()
alicePovTx!!.userHasVerifiedShortCode() alicePovTx!!.userHasVerifiedShortCode()
testHelper.waitWithLatch { testHelper.waitWithLatch("Timeout waiting for alice to view bob as trusted") {
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(it) {
alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId) alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId)
} }
} }
testHelper.waitWithLatch { // Should this not be bob to see alice as trusted?
testHelper.waitWithLatch("Timeout waiting for alice to view bob as trusted") {
testHelper.retryPeriodicallyWithLatch(it) { testHelper.retryPeriodicallyWithLatch(it) {
alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId) alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId)
} }

View File

@@ -23,7 +23,9 @@ import org.amshove.kluent.fail
import org.amshove.kluent.internal.assertEquals import org.amshove.kluent.internal.assertEquals
import org.junit.Assert import org.junit.Assert
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.rules.Timeout
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.junit.runners.JUnit4 import org.junit.runners.JUnit4
import org.junit.runners.MethodSorters import org.junit.runners.MethodSorters
@@ -58,6 +60,9 @@ import org.matrix.android.sdk.common.TestMatrixCallback
@LargeTest @LargeTest
class E2eeSanityTests : InstrumentedTest { class E2eeSanityTests : InstrumentedTest {
@Rule @JvmField val timeout = Timeout.seconds(120)
private val testHelper = CommonTestHelper(context()) private val testHelper = CommonTestHelper(context())
private val cryptoTestHelper = CryptoTestHelper(testHelper) private val cryptoTestHelper = CryptoTestHelper(testHelper)