diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt index da14b21f3c..386787b882 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/common/CommonTestHelper.kt @@ -28,7 +28,10 @@ import im.vector.matrix.android.api.auth.data.LoginFlowResult import im.vector.matrix.android.api.auth.registration.RegistrationResult import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.events.model.EventType +import im.vector.matrix.android.api.session.events.model.LocalEcho +import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.Room +import im.vector.matrix.android.api.session.room.model.message.MessageContent import im.vector.matrix.android.api.session.room.timeline.Timeline import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineSettings @@ -113,7 +116,7 @@ class CommonTestHelper(context: Context) { fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List { val sentEvents = ArrayList(nbOfMessages) val latch = CountDownLatch(nbOfMessages) - val onEventSentListener = object : Timeline.Listener { + val timelineListener = object : Timeline.Listener { override fun onTimelineFailure(throwable: Throwable) { } @@ -122,21 +125,25 @@ class CommonTestHelper(context: Context) { } override fun onTimelineUpdated(snapshot: List) { - // TODO Count only new messages? - if (snapshot.count { it.root.type == EventType.MESSAGE } == nbOfMessages) { - sentEvents.addAll(snapshot.filter { it.root.type == EventType.MESSAGE }) + val newMessages = snapshot + .filter { LocalEcho.isLocalEchoId(it.eventId).not() } + .filter { it.root.getClearType() == EventType.MESSAGE } + .filter { it.root.getClearContent().toModel()?.body?.startsWith(message) == true } + + if (newMessages.size == nbOfMessages) { + sentEvents.addAll(newMessages) latch.countDown() } } } val timeline = room.createTimeline(null, TimelineSettings(10)) timeline.start() - timeline.addListener(onEventSentListener) + timeline.addListener(timelineListener) for (i in 0 until nbOfMessages) { room.sendTextMessage(message + " #" + (i + 1)) } await(latch) - timeline.removeListener(onEventSentListener) + timeline.removeListener(timelineListener) timeline.dispose() // Check that all events has been created diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt index e0c7e8273a..77ba66d341 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackupTest.kt @@ -861,6 +861,7 @@ class KeysBackupTest : InstrumentedTest { */ @Test fun testCheckAndStartKeysBackupWhenRestartingAMatrixSession() { + fail("This test still fail. To investigate") // - Create a backup version val cryptoTestData = mCryptoTestHelper.doE2ETestWithAliceAndBobInARoomWithEncryptedMessages() @@ -1011,9 +1012,6 @@ class KeysBackupTest : InstrumentedTest { val oldKeyBackupVersion = keysBackup.currentBackupVersion val aliceUserId = cryptoTestData.firstSession.myUserId - // Close first Alice session, else they will share the same Crypto store and the test fails. - cryptoTestData.firstSession.close() - // - Log Alice on a new device val aliceSession2 = mTestHelper.logIntoAccount(aliceUserId, defaultSessionParamsWithInitialSync)