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 ->
|
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)
|
alice.sendTextMessage(SharedState.sharedRoom, message.content, isEncrypted)
|
||||||
bob.expectTextMessage(SharedState.sharedRoom, message)
|
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)
|
bob.sendTextMessage(SharedState.sharedRoom, message2.content, isEncrypted)
|
||||||
alice.expectTextMessage(SharedState.sharedRoom, message2)
|
alice.expectTextMessage(SharedState.sharedRoom, message2)
|
||||||
|
|
||||||
val aliceSecondDevice = testMatrix(SharedState.alice).also { it.newlogin() }
|
val aliceSecondDevice = testMatrix(SharedState.alice).also { it.newlogin() }
|
||||||
aliceSecondDevice.client.syncService().startSyncing().collectAsync {
|
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)
|
alice.sendTextMessage(SharedState.sharedRoom, message3.content, isEncrypted)
|
||||||
aliceSecondDevice.expectTextMessage(SharedState.sharedRoom, message3)
|
aliceSecondDevice.expectTextMessage(SharedState.sharedRoom, message3)
|
||||||
bob.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)
|
aliceSecondDevice.sendTextMessage(SharedState.sharedRoom, message4.content, isEncrypted)
|
||||||
alice.expectTextMessage(SharedState.sharedRoom, message4)
|
alice.expectTextMessage(SharedState.sharedRoom, message4)
|
||||||
bob.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 TestUser(val password: String, val roomMember: RoomMember, val homeServer: String)
|
||||||
data class TestMessage(val content: String, val author: RoomMember)
|
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) {
|
fun testAfterInitialSync(block: suspend MatrixTestScope.(TestMatrix, TestMatrix) -> Unit) {
|
||||||
restoreLoginAndInitialSync(TestMatrix(SharedState.alice, includeLogging = false), TestMatrix(SharedState.bob, includeLogging = false), block)
|
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 collected = mutableListOf<T>()
|
||||||
val work = testScope.async {
|
val work = testScope.async {
|
||||||
flow.onEach {
|
flow.onEach {
|
||||||
|
println("found: $it")
|
||||||
collected.add(it)
|
collected.add(it)
|
||||||
}.first { it == expected }
|
}.first { it == expected }
|
||||||
}
|
}
|
||||||
|
@ -124,12 +125,14 @@ class MatrixTestScope(private val testScope: TestScope) {
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun TestMatrix.expectTextMessage(roomId: RoomId, message: TestMessage) {
|
suspend fun TestMatrix.expectTextMessage(roomId: RoomId, message: TestMessage) {
|
||||||
|
println("expecting ${message.content}")
|
||||||
this.client.syncService().room(roomId)
|
this.client.syncService().room(roomId)
|
||||||
.map { it.events.filterIsInstance<RoomEvent.Message>().map { TestMessage(it.content, it.author) }.firstOrNull() }
|
.map { it.events.filterIsInstance<RoomEvent.Message>().map { TestMessage(it.content, it.author) }.firstOrNull() }
|
||||||
.assert(message)
|
.assert(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun TestMatrix.sendTextMessage(roomId: RoomId, content: String, isEncrypted: Boolean) {
|
suspend fun TestMatrix.sendTextMessage(roomId: RoomId, content: String, isEncrypted: Boolean) {
|
||||||
|
println("sending $content")
|
||||||
this.client.messageService().scheduleMessage(
|
this.client.messageService().scheduleMessage(
|
||||||
MessageService.Message.TextMessage(
|
MessageService.Message.TextMessage(
|
||||||
content = MessageService.Message.Content.TextContent(body = content),
|
content = MessageService.Message.Content.TextContent(body = content),
|
||||||
|
|
Loading…
Reference in New Issue