using uuids instead of timestamps for unique test messages
This commit is contained in:
parent
4d43b6e31f
commit
a9ef2b5190
|
@ -95,22 +95,22 @@ class SmokeTest {
|
|||
}
|
||||
|
||||
private fun testTextMessaging(isEncrypted: Boolean) = testAfterInitialSync { alice, bob ->
|
||||
val message = "from alice to bob : ${System.currentTimeMillis()}".from(SharedState.alice.roomMember)
|
||||
val message = "from alice to bob".from(SharedState.alice.roomMember)
|
||||
alice.sendTextMessage(SharedState.sharedRoom, message.content, isEncrypted)
|
||||
bob.expectTextMessage(SharedState.sharedRoom, message)
|
||||
|
||||
val message2 = "from bob to alice : ${System.currentTimeMillis()}".from(SharedState.bob.roomMember)
|
||||
val message2 = "from bob to alice".from(SharedState.bob.roomMember)
|
||||
bob.sendTextMessage(SharedState.sharedRoom, message2.content, isEncrypted)
|
||||
alice.expectTextMessage(SharedState.sharedRoom, message2)
|
||||
|
||||
val aliceSecondDevice = testMatrix(SharedState.alice).also { it.newlogin() }
|
||||
aliceSecondDevice.client.syncService().startSyncing().collectAsync {
|
||||
val message3 = "from alice to bob and alice's second device : ${System.currentTimeMillis()}".from(SharedState.alice.roomMember)
|
||||
val message3 = "from alice to bob and alice's second device".from(SharedState.alice.roomMember)
|
||||
alice.sendTextMessage(SharedState.sharedRoom, message3.content, isEncrypted)
|
||||
aliceSecondDevice.expectTextMessage(SharedState.sharedRoom, message3)
|
||||
bob.expectTextMessage(SharedState.sharedRoom, message3)
|
||||
|
||||
val message4 = "from alice's second device to bob and alice's first device : ${System.currentTimeMillis()}".from(SharedState.alice.roomMember)
|
||||
val message4 = "from alice's second device to bob and alice's first device".from(SharedState.alice.roomMember)
|
||||
aliceSecondDevice.sendTextMessage(SharedState.sharedRoom, message4.content, isEncrypted)
|
||||
alice.expectTextMessage(SharedState.sharedRoom, message4)
|
||||
bob.expectTextMessage(SharedState.sharedRoom, message4)
|
||||
|
@ -169,7 +169,7 @@ object SharedState {
|
|||
data class TestUser(val password: String, val roomMember: RoomMember, val homeServer: String)
|
||||
data class TestMessage(val content: String, val author: RoomMember)
|
||||
|
||||
fun String.from(roomMember: RoomMember) = TestMessage(this, roomMember)
|
||||
fun String.from(roomMember: RoomMember) = TestMessage("$this - ${UUID.randomUUID()}", roomMember)
|
||||
|
||||
fun testAfterInitialSync(block: suspend MatrixTestScope.(TestMatrix, TestMatrix) -> Unit) {
|
||||
restoreLoginAndInitialSync(TestMatrix(SharedState.alice, includeLogging = false), TestMatrix(SharedState.bob, includeLogging = false), block)
|
||||
|
|
|
@ -104,6 +104,7 @@ class MatrixTestScope(private val testScope: TestScope) {
|
|||
val collected = mutableListOf<T>()
|
||||
val work = testScope.async {
|
||||
flow.onEach {
|
||||
println("found: $it")
|
||||
collected.add(it)
|
||||
}.first { it == expected }
|
||||
}
|
||||
|
@ -124,12 +125,14 @@ class MatrixTestScope(private val testScope: TestScope) {
|
|||
}
|
||||
|
||||
suspend fun TestMatrix.expectTextMessage(roomId: RoomId, message: TestMessage) {
|
||||
println("expecting ${message.content}")
|
||||
this.client.syncService().room(roomId)
|
||||
.map { it.events.filterIsInstance<RoomEvent.Message>().map { TestMessage(it.content, it.author) }.firstOrNull() }
|
||||
.assert(message)
|
||||
}
|
||||
|
||||
suspend fun TestMatrix.sendTextMessage(roomId: RoomId, content: String, isEncrypted: Boolean) {
|
||||
println("sending $content")
|
||||
this.client.messageService().scheduleMessage(
|
||||
MessageService.Message.TextMessage(
|
||||
content = MessageService.Message.Content.TextContent(body = content),
|
||||
|
|
Loading…
Reference in New Issue