fix integration test

This commit is contained in:
ariskotsomitopoulos 2022-01-07 16:28:58 +02:00
parent ac5caccdf9
commit ae81f61958

View file

@ -157,7 +157,7 @@ class CommonTestHelper(context: Context) {
/** /**
* Will send nb of messages provided by count parameter but waits every 10 messages to avoid gap in sync * Will send nb of messages provided by count parameter but waits every 10 messages to avoid gap in sync
*/ */
private fun sendTextMessagesBatched(timeline: Timeline, room: Room, message: String, count: Int, timeout: Long,rootThreadEventId: String? = null): List<TimelineEvent> { private fun sendTextMessagesBatched(timeline: Timeline, room: Room, message: String, count: Int, timeout: Long, rootThreadEventId: String? = null): List<TimelineEvent> {
val sentEvents = ArrayList<TimelineEvent>(count) val sentEvents = ArrayList<TimelineEvent>(count)
(1 until count + 1) (1 until count + 1)
.map { "$message #$it" } .map { "$message #$it" }
@ -214,37 +214,9 @@ class CommonTestHelper(context: Context) {
numberOfMessages: Int, numberOfMessages: Int,
rootThreadEventId: String, rootThreadEventId: String,
timeout: Long = TestConstants.timeOutMillis): List<TimelineEvent> { timeout: Long = TestConstants.timeOutMillis): List<TimelineEvent> {
val sentEvents = ArrayList<TimelineEvent>(numberOfMessages)
val timeline = room.createTimeline(null, TimelineSettings(10)) val timeline = room.createTimeline(null, TimelineSettings(10))
timeline.start() timeline.start()
waitWithLatch(timeout + 1_000L * numberOfMessages) { latch -> val sentEvents = sendTextMessagesBatched(timeline, room, message, numberOfMessages, timeout,rootThreadEventId)
val timelineListener = object : Timeline.Listener {
override fun onTimelineFailure(throwable: Throwable) {
}
override fun onNewTimelineEvents(eventIds: List<String>) {
// noop
}
override fun onTimelineUpdated(snapshot: List<TimelineEvent>) {
val newMessages = snapshot
.filter { it.root.sendState == SendState.SYNCED }
.filter { it.root.getClearType() == EventType.MESSAGE }
.filter { it.root.getClearContent().toModel<MessageContent>()?.body?.startsWith(message) == true }
Timber.v("New synced message size: ${newMessages.size}")
if (newMessages.size == numberOfMessages) {
sentEvents.addAll(newMessages)
// Remove listener now, if not at the next update sendEvents could change
timeline.removeListener(this)
latch.countDown()
}
}
}
timeline.addListener(timelineListener)
sendTextMessagesBatched(room, message, numberOfMessages, rootThreadEventId)
}
timeline.dispose() timeline.dispose()
// Check that all events has been created // Check that all events has been created
assertEquals("Message number do not match $sentEvents", numberOfMessages.toLong(), sentEvents.size.toLong()) assertEquals("Message number do not match $sentEvents", numberOfMessages.toLong(), sentEvents.size.toLong())