Support testing a room with many members.
This commit is contained in:
parent
7e4725c091
commit
427dc784fe
|
@ -19,7 +19,7 @@ package org.matrix.android.sdk.common
|
|||
import org.matrix.android.sdk.api.session.Session
|
||||
|
||||
data class CryptoTestData(val roomId: String,
|
||||
val sessions: List<Session> = emptyList()) {
|
||||
val sessions: MutableList<Session> = mutableListOf()) {
|
||||
|
||||
val firstSession: Session
|
||||
get() = sessions.first()
|
||||
|
|
|
@ -73,7 +73,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
}
|
||||
}
|
||||
|
||||
return CryptoTestData(roomId, listOf(aliceSession))
|
||||
return CryptoTestData(roomId, mutableListOf(aliceSession))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,7 +139,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
// assertNotNull(roomFromBobPOV.powerLevels)
|
||||
// assertTrue(roomFromBobPOV.powerLevels.maySendMessage(bobSession.myUserId))
|
||||
|
||||
return CryptoTestData(aliceRoomId, listOf(aliceSession, bobSession))
|
||||
return CryptoTestData(aliceRoomId, mutableListOf(aliceSession, bobSession))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,7 +157,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
// wait the initial sync
|
||||
SystemClock.sleep(1000)
|
||||
|
||||
return CryptoTestData(aliceRoomId, listOf(aliceSession, cryptoTestData.secondSession!!, samSession))
|
||||
return CryptoTestData(aliceRoomId, mutableListOf(aliceSession, cryptoTestData.secondSession!!, samSession))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -381,4 +381,31 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doE2ETestWithManyMembers(numberOfMembers: Int): CryptoTestData {
|
||||
val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams)
|
||||
aliceSession.cryptoService().setWarnOnUnknownDevices(false)
|
||||
|
||||
val roomId = mTestHelper.doSync<String> {
|
||||
aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }, it)
|
||||
}
|
||||
val room = aliceSession.getRoom(roomId)!!
|
||||
|
||||
mTestHelper.runBlockingTest {
|
||||
room.enableEncryption()
|
||||
}
|
||||
|
||||
val cryptoTestData = CryptoTestData(roomId, mutableListOf(aliceSession))
|
||||
for (index in 1 until numberOfMembers) {
|
||||
mTestHelper
|
||||
.createAccount("User_$index", defaultSessionParams)
|
||||
.also { session -> mTestHelper.doSync<Unit> { 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") }
|
||||
.also { session -> cryptoTestData.sessions.add(session) }
|
||||
}
|
||||
|
||||
return cryptoTestData
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
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
|
||||
|
@ -29,11 +31,14 @@ 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
|
||||
|
||||
@RunWith(JUnit4::class)
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
class TimelineWithManyMembersTest : InstrumentedTest {
|
||||
|
||||
private val NUMBER_OF_MEMBERS = 5
|
||||
|
||||
private val commonTestHelper = CommonTestHelper(context())
|
||||
private val cryptoTestHelper = CryptoTestHelper(commonTestHelper)
|
||||
|
||||
|
@ -91,4 +96,42 @@ class TimelineWithManyMembersTest : InstrumentedTest {
|
|||
}
|
||||
samSession.stopSync()
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures when someone sends a message to a crowded room, everyone can decrypt the message.
|
||||
*/
|
||||
@Test
|
||||
fun everyone_should_decrypt_message_in_a_crowded_room() {
|
||||
val cryptoTestData = cryptoTestHelper.doE2ETestWithManyMembers(NUMBER_OF_MEMBERS)
|
||||
|
||||
val sessionForFirstMember = cryptoTestData.firstSession
|
||||
val roomForFirstMember = sessionForFirstMember.getRoom(cryptoTestData.roomId)!!
|
||||
|
||||
val firstMessage = "First messages from Alice"
|
||||
commonTestHelper.sendTextMessage(
|
||||
roomForFirstMember,
|
||||
firstMessage,
|
||||
1)
|
||||
|
||||
for (index in 1 until cryptoTestData.sessions.size) {
|
||||
val session = cryptoTestData.sessions[index]
|
||||
val roomForCurrentMember = session.getRoom(cryptoTestData.roomId)!!
|
||||
val timelineForCurrentMember = roomForCurrentMember.createTimeline(null, TimelineSettings(30))
|
||||
timelineForCurrentMember.start()
|
||||
|
||||
session.startSync(true)
|
||||
|
||||
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()
|
||||
}
|
||||
timelineForCurrentMember.addListener(eventsListener)
|
||||
commonTestHelper.await(lock)
|
||||
}
|
||||
session.stopSync()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue