Improve test with detailed CryptoError message.
This commit is contained in:
parent
427dc784fe
commit
b263273c87
|
@ -119,7 +119,7 @@ class CommonTestHelper(context: Context) {
|
|||
* @param message the message to send
|
||||
* @param nbOfMessages the number of time the message will be sent
|
||||
*/
|
||||
fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List<TimelineEvent> {
|
||||
fun sendTextMessage(room: Room, message: String, nbOfMessages: Int, timeout: Long = TestConstants.timeOutMillis): List<TimelineEvent> {
|
||||
val timeline = room.createTimeline(null, TimelineSettings(10))
|
||||
val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
|
||||
val latch = CountDownLatch(1)
|
||||
|
@ -151,7 +151,7 @@ class CommonTestHelper(context: Context) {
|
|||
room.sendTextMessage(message + " #" + (i + 1))
|
||||
}
|
||||
// Wait 3 second more per message
|
||||
await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages)
|
||||
await(latch, timeout = timeout + 3_000L * nbOfMessages)
|
||||
timeline.dispose()
|
||||
|
||||
// Check that all events has been created
|
||||
|
|
|
@ -399,7 +399,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
for (index in 1 until numberOfMembers) {
|
||||
mTestHelper
|
||||
.createAccount("User_$index", defaultSessionParams)
|
||||
.also { session -> mTestHelper.doSync<Unit> { room.invite(session.myUserId, null, it) } }
|
||||
.also { session -> mTestHelper.doSync<Unit>(timeout = 600_000) { room.invite(session.myUserId, null, it) } }
|
||||
.also { println("TEST -> " + it.myUserId + " invited") }
|
||||
.also { session -> mTestHelper.doSync<Unit> { session.joinRoom(room.roomId, null, emptyList(), it) } }
|
||||
.also { println("TEST -> " + it.myUserId + " joined") }
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.matrix.android.sdk.session.room.timeline
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -31,7 +29,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
|||
import org.matrix.android.sdk.common.CommonTestHelper
|
||||
import org.matrix.android.sdk.common.CryptoTestHelper
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.fail
|
||||
|
||||
@RunWith(JUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
|
@ -111,7 +109,9 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
|||
commonTestHelper.sendTextMessage(
|
||||
roomForFirstMember,
|
||||
firstMessage,
|
||||
1)
|
||||
1,
|
||||
600_000
|
||||
)
|
||||
|
||||
for (index in 1 until cryptoTestData.sessions.size) {
|
||||
val session = cryptoTestData.sessions[index]
|
||||
|
@ -124,12 +124,19 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
|||
run {
|
||||
val lock = CountDownLatch(1)
|
||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||
val decryptedMessage = snapshot.firstOrNull()?.root?.getClearContent()?.toModel<MessageContent>()?.body
|
||||
println("Decrypted Message: $decryptedMessage")
|
||||
return@createEventListener decryptedMessage?.startsWith(firstMessage).orFalse()
|
||||
snapshot
|
||||
.find { it.isEncrypted() }
|
||||
?.let {
|
||||
val body = it.root.getClearContent()?.toModel<MessageContent>()?.body
|
||||
if (body?.startsWith(firstMessage).orFalse()) {
|
||||
return@createEventListener true
|
||||
} else {
|
||||
fail("User " + session.myUserId + " decrypted as " + body + " CryptoError: " + it.root.mCryptoError)
|
||||
}
|
||||
} ?: return@createEventListener false
|
||||
}
|
||||
timelineForCurrentMember.addListener(eventsListener)
|
||||
commonTestHelper.await(lock)
|
||||
commonTestHelper.await(lock, 600_000)
|
||||
}
|
||||
session.stopSync()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue