mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 14:08:44 +03:00
Improve test with detailed CryptoError message.
This commit is contained in:
parent
427dc784fe
commit
b263273c87
3 changed files with 18 additions and 11 deletions
|
@ -119,7 +119,7 @@ class CommonTestHelper(context: Context) {
|
||||||
* @param message the message to send
|
* @param message the message to send
|
||||||
* @param nbOfMessages the number of time the message will be sent
|
* @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 timeline = room.createTimeline(null, TimelineSettings(10))
|
||||||
val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
|
val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
|
@ -151,7 +151,7 @@ class CommonTestHelper(context: Context) {
|
||||||
room.sendTextMessage(message + " #" + (i + 1))
|
room.sendTextMessage(message + " #" + (i + 1))
|
||||||
}
|
}
|
||||||
// Wait 3 second more per message
|
// Wait 3 second more per message
|
||||||
await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages)
|
await(latch, timeout = timeout + 3_000L * nbOfMessages)
|
||||||
timeline.dispose()
|
timeline.dispose()
|
||||||
|
|
||||||
// Check that all events has been created
|
// Check that all events has been created
|
||||||
|
|
|
@ -399,7 +399,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
||||||
for (index in 1 until numberOfMembers) {
|
for (index in 1 until numberOfMembers) {
|
||||||
mTestHelper
|
mTestHelper
|
||||||
.createAccount("User_$index", defaultSessionParams)
|
.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 { println("TEST -> " + it.myUserId + " invited") }
|
||||||
.also { session -> mTestHelper.doSync<Unit> { session.joinRoom(room.roomId, null, emptyList(), it) } }
|
.also { session -> mTestHelper.doSync<Unit> { session.joinRoom(room.roomId, null, emptyList(), it) } }
|
||||||
.also { println("TEST -> " + it.myUserId + " joined") }
|
.also { println("TEST -> " + it.myUserId + " joined") }
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.matrix.android.sdk.session.room.timeline
|
package org.matrix.android.sdk.session.room.timeline
|
||||||
|
|
||||||
import android.os.SystemClock
|
|
||||||
import android.util.Log
|
|
||||||
import org.junit.FixMethodOrder
|
import org.junit.FixMethodOrder
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
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.CommonTestHelper
|
||||||
import org.matrix.android.sdk.common.CryptoTestHelper
|
import org.matrix.android.sdk.common.CryptoTestHelper
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.fail
|
||||||
|
|
||||||
@RunWith(JUnit4::class)
|
@RunWith(JUnit4::class)
|
||||||
@FixMethodOrder(MethodSorters.JVM)
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
|
@ -111,7 +109,9 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
||||||
commonTestHelper.sendTextMessage(
|
commonTestHelper.sendTextMessage(
|
||||||
roomForFirstMember,
|
roomForFirstMember,
|
||||||
firstMessage,
|
firstMessage,
|
||||||
1)
|
1,
|
||||||
|
600_000
|
||||||
|
)
|
||||||
|
|
||||||
for (index in 1 until cryptoTestData.sessions.size) {
|
for (index in 1 until cryptoTestData.sessions.size) {
|
||||||
val session = cryptoTestData.sessions[index]
|
val session = cryptoTestData.sessions[index]
|
||||||
|
@ -124,12 +124,19 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
||||||
run {
|
run {
|
||||||
val lock = CountDownLatch(1)
|
val lock = CountDownLatch(1)
|
||||||
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
|
||||||
val decryptedMessage = snapshot.firstOrNull()?.root?.getClearContent()?.toModel<MessageContent>()?.body
|
snapshot
|
||||||
println("Decrypted Message: $decryptedMessage")
|
.find { it.isEncrypted() }
|
||||||
return@createEventListener decryptedMessage?.startsWith(firstMessage).orFalse()
|
?.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)
|
timelineForCurrentMember.addListener(eventsListener)
|
||||||
commonTestHelper.await(lock)
|
commonTestHelper.await(lock, 600_000)
|
||||||
}
|
}
|
||||||
session.stopSync()
|
session.stopSync()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue