mirror of
https://github.com/vector-im/riotX-android
synced 2025-10-06 00:02:48 +02:00
Compare commits
1 Commits
v1.5.25
...
michaelk/a
Author | SHA1 | Date | |
---|---|---|---|
|
14e7c71b26 |
@@ -111,7 +111,7 @@ class CommonTestHelper(context: Context) {
|
||||
}
|
||||
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
|
||||
*/
|
||||
fun clearCacheAndSync(session: Session, timeout: Long = TestConstants.timeOutMillis) {
|
||||
waitWithLatch(timeout) { latch ->
|
||||
waitWithLatch("Timeout waiting to clear cache and sync", timeout) { latch ->
|
||||
session.clearCache()
|
||||
val syncLiveData = session.getSyncStateLive()
|
||||
val syncObserver = object : Observer<SyncState> {
|
||||
@@ -172,7 +172,7 @@ class CommonTestHelper(context: Context) {
|
||||
room.sendService().sendTextMessage(formattedMessage)
|
||||
}
|
||||
}
|
||||
waitWithLatch(timeout) { latch ->
|
||||
waitWithLatch("Timeout waiting for batch of messages to send", timeout) { latch ->
|
||||
val timelineListener = object : Timeline.Listener {
|
||||
|
||||
override fun onTimelineUpdated(snapshot: List<TimelineEvent>) {
|
||||
@@ -374,8 +374,8 @@ class CommonTestHelper(context: Context) {
|
||||
* @param latch
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
fun await(latch: CountDownLatch, timeout: Long? = TestConstants.timeOutMillis) {
|
||||
assertTrue(latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
||||
fun await(message: String, latch: CountDownLatch, timeout: Long? = TestConstants.timeOutMillis) {
|
||||
assertTrue(message, latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
||||
}
|
||||
|
||||
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)
|
||||
coroutineScope.launch(dispatcher) {
|
||||
block(latch)
|
||||
}
|
||||
await(latch, timeout)
|
||||
await(message, latch, timeout)
|
||||
}
|
||||
|
||||
fun <T> runBlockingTest(timeout: Long = TestConstants.timeOutMillis, block: suspend () -> T): T {
|
||||
@@ -418,7 +418,7 @@ class CommonTestHelper(context: Context) {
|
||||
|
||||
block.invoke(callback)
|
||||
|
||||
await(lock, timeout)
|
||||
await("Timeout waiting for sync", lock, timeout)
|
||||
|
||||
assertNotNull(result)
|
||||
return result!!
|
||||
|
@@ -68,7 +68,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
aliceSession.roomService().createRoom(CreateRoomParams().apply { name = "MyRoom" })
|
||||
}
|
||||
if (encryptedRoom) {
|
||||
testHelper.waitWithLatch { latch ->
|
||||
testHelper.waitWithLatch("Wait for encryption to be enabled in room") { latch ->
|
||||
val room = aliceSession.getRoom(roomId)!!
|
||||
room.roomCryptoService().enableEncryption()
|
||||
val roomSummaryLive = room.getRoomSummaryLive()
|
||||
@@ -98,7 +98,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
|
||||
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 newRoomObserver = object : Observer<List<RoomSummary>> {
|
||||
override fun onChanged(t: List<RoomSummary>?) {
|
||||
@@ -112,7 +112,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
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 roomJoinedObserver = object : Observer<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 {
|
||||
var roomId: String = ""
|
||||
testHelper.waitWithLatch { latch ->
|
||||
testHelper.waitWithLatch("Timeout waiting for bob to see DM from alice") { latch ->
|
||||
roomId = alice.roomService().createDirectRoom(bob.myUserId)
|
||||
val bobRoomSummariesLive = bob.roomService().getRoomSummariesLive(roomSummaryQueryParams { })
|
||||
val newRoomObserver = object : Observer<List<RoomSummary>> {
|
||||
@@ -257,7 +257,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
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 newRoomObserver = object : Observer<List<RoomSummary>> {
|
||||
override fun onChanged(t: List<RoomSummary>?) {
|
||||
@@ -315,7 +315,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
var bobPovTx: IncomingSasVerificationTransaction? = null
|
||||
|
||||
// wait for alice to get the ready
|
||||
testHelper.waitWithLatch {
|
||||
testHelper.waitWithLatch("Timeout waiting for bob to see verification started") {
|
||||
testHelper.retryPeriodicallyWithLatch(it) {
|
||||
bobPovTx = bobVerificationService.getExistingTransaction(alice.myUserId, requestID) as? IncomingSasVerificationTransaction
|
||||
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) {
|
||||
alicePovTx = aliceVerificationService.getExistingTransaction(bob.myUserId, requestID) as? OutgoingSasVerificationTransaction
|
||||
Log.v("TEST", "== alicePovTx is ${alicePovTx?.uxState}")
|
||||
@@ -336,7 +336,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
}
|
||||
}
|
||||
// wait for alice to get the ready
|
||||
testHelper.waitWithLatch {
|
||||
testHelper.waitWithLatch("Timeout waiting for bob to be ShortCodeReady") {
|
||||
testHelper.retryPeriodicallyWithLatch(it) {
|
||||
bobPovTx = bobVerificationService.getExistingTransaction(alice.myUserId, requestID) as? IncomingSasVerificationTransaction
|
||||
Log.v("TEST", "== bobPovTx is ${alicePovTx?.uxState}")
|
||||
@@ -352,13 +352,14 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
||||
bobPovTx!!.userHasVerifiedShortCode()
|
||||
alicePovTx!!.userHasVerifiedShortCode()
|
||||
|
||||
testHelper.waitWithLatch {
|
||||
testHelper.waitWithLatch("Timeout waiting for alice to view bob as trusted") {
|
||||
testHelper.retryPeriodicallyWithLatch(it) {
|
||||
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) {
|
||||
alice.cryptoService().crossSigningService().isUserTrusted(bob.myUserId)
|
||||
}
|
||||
|
@@ -23,7 +23,9 @@ import org.amshove.kluent.fail
|
||||
import org.amshove.kluent.internal.assertEquals
|
||||
import org.junit.Assert
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.Timeout
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.junit.runners.MethodSorters
|
||||
@@ -58,6 +60,9 @@ import org.matrix.android.sdk.common.TestMatrixCallback
|
||||
@LargeTest
|
||||
class E2eeSanityTests : InstrumentedTest {
|
||||
|
||||
@Rule @JvmField val timeout = Timeout.seconds(120)
|
||||
|
||||
|
||||
private val testHelper = CommonTestHelper(context())
|
||||
private val cryptoTestHelper = CryptoTestHelper(testHelper)
|
||||
|
||||
|
Reference in New Issue
Block a user