Tests: clean after review
This commit is contained in:
parent
30fe564a2c
commit
51f46d199f
@ -1 +0,0 @@
|
|||||||
Make the verification shields the same in Element Web and Element Android
|
|
1
changelog.d/4546.bugfix
Normal file
1
changelog.d/4546.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix lots of integration tests by introducing TestMatrix class and MatrixWorkerFactory.
|
@ -359,7 +359,6 @@ class CommonTestHelper(context: Context) {
|
|||||||
assertTrue(latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
assertTrue(latch.await(timeout ?: TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
suspend fun retryPeriodicallyWithLatch(latch: CountDownLatch, condition: (() -> Boolean)) {
|
suspend fun retryPeriodicallyWithLatch(latch: CountDownLatch, condition: (() -> Boolean)) {
|
||||||
while (true) {
|
while (true) {
|
||||||
delay(1000)
|
delay(1000)
|
||||||
|
@ -88,7 +88,6 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
|
|||||||
/**
|
/**
|
||||||
* @return alice and bob sessions
|
* @return alice and bob sessions
|
||||||
*/
|
*/
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun doE2ETestWithAliceAndBobInARoom(encryptedRoom: Boolean = true): CryptoTestData {
|
fun doE2ETestWithAliceAndBobInARoom(encryptedRoom: Boolean = true): CryptoTestData {
|
||||||
val cryptoTestData = doE2ETestWithAliceInARoom(encryptedRoom)
|
val cryptoTestData = doE2ETestWithAliceInARoom(encryptedRoom)
|
||||||
val aliceSession = cryptoTestData.firstSession
|
val aliceSession = cryptoTestData.firstSession
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.common
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force foreground for testing
|
||||||
|
*/
|
||||||
|
internal class TestBackgroundDetectionObserver : BackgroundDetectionObserver {
|
||||||
|
|
||||||
|
override val isInBackground: Boolean = false
|
||||||
|
|
||||||
|
override fun register(listener: BackgroundDetectionObserver.Listener) = Unit
|
||||||
|
|
||||||
|
override fun unregister(listener: BackgroundDetectionObserver.Listener) = Unit
|
||||||
|
}
|
@ -24,7 +24,6 @@ import org.matrix.android.sdk.internal.di.MatrixScope
|
|||||||
import org.matrix.android.sdk.internal.session.MockHttpInterceptor
|
import org.matrix.android.sdk.internal.session.MockHttpInterceptor
|
||||||
import org.matrix.android.sdk.internal.session.TestInterceptor
|
import org.matrix.android.sdk.internal.session.TestInterceptor
|
||||||
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
|
import org.matrix.android.sdk.internal.util.BackgroundDetectionObserver
|
||||||
import org.matrix.android.sdk.internal.util.TestBackgroundDetectionObserver
|
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
internal abstract class TestModule {
|
internal abstract class TestModule {
|
||||||
|
@ -263,7 +263,6 @@ class QuadSTests : InstrumentedTest {
|
|||||||
testHelper.signOutAndClose(aliceSession)
|
testHelper.signOutAndClose(aliceSession)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
private fun assertAccountData(session: Session, type: String): UserAccountDataEvent {
|
private fun assertAccountData(session: Session, type: String): UserAccountDataEvent {
|
||||||
var accountData: UserAccountDataEvent? = null
|
var accountData: UserAccountDataEvent? = null
|
||||||
testHelper.waitWithLatch {
|
testHelper.waitWithLatch {
|
||||||
|
@ -48,7 +48,6 @@ class SpaceCreationTest : InstrumentedTest {
|
|||||||
private val commonTestHelper = CommonTestHelper(context())
|
private val commonTestHelper = CommonTestHelper(context())
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun createSimplePublicSpace() {
|
fun createSimplePublicSpace() {
|
||||||
val session = commonTestHelper.createAccount("Hubble", SessionTestParams(true))
|
val session = commonTestHelper.createAccount("Hubble", SessionTestParams(true))
|
||||||
val roomName = "My Space"
|
val roomName = "My Space"
|
||||||
@ -130,7 +129,6 @@ class SpaceCreationTest : InstrumentedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun testSimplePublicSpaceWithChildren() {
|
fun testSimplePublicSpaceWithChildren() {
|
||||||
val aliceSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
val aliceSession = commonTestHelper.createAccount("alice", SessionTestParams(true))
|
||||||
val bobSession = commonTestHelper.createAccount("bob", SessionTestParams(true))
|
val bobSession = commonTestHelper.createAccount("bob", SessionTestParams(true))
|
||||||
|
@ -53,7 +53,6 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||||||
private val commonTestHelper = CommonTestHelper(context())
|
private val commonTestHelper = CommonTestHelper(context())
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun createCanonicalChildRelation() {
|
fun createCanonicalChildRelation() {
|
||||||
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
||||||
val spaceName = "My Space"
|
val spaceName = "My Space"
|
||||||
@ -170,7 +169,6 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun testFilteringBySpace() {
|
fun testFilteringBySpace() {
|
||||||
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
||||||
|
|
||||||
@ -246,7 +244,6 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun testBreakCycle() {
|
fun testBreakCycle() {
|
||||||
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
||||||
|
|
||||||
@ -290,7 +287,6 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE")
|
|
||||||
fun testLiveFlatChildren() {
|
fun testLiveFlatChildren() {
|
||||||
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
val session = commonTestHelper.createAccount("John", SessionTestParams(true))
|
||||||
|
|
||||||
|
@ -34,9 +34,7 @@ internal class SyncTokenStore @Inject constructor(@SessionDatabase private val m
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveToken(realm: Realm, token: String?) {
|
fun saveToken(realm: Realm, token: String?) {
|
||||||
if (realm.isInTransaction) {
|
val sync = SyncEntity(token)
|
||||||
val sync = SyncEntity(token)
|
realm.insertOrUpdate(sync)
|
||||||
realm.insertOrUpdate(sync)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,15 +59,3 @@ internal class DefaultBackgroundDetectionObserver : BackgroundDetectionObserver
|
|||||||
listeners.forEach { it.onMoveToBackground() }
|
listeners.forEach { it.onMoveToBackground() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Force foreground for testing
|
|
||||||
*/
|
|
||||||
internal class TestBackgroundDetectionObserver : BackgroundDetectionObserver {
|
|
||||||
|
|
||||||
override val isInBackground: Boolean = false
|
|
||||||
|
|
||||||
override fun register(listener: BackgroundDetectionObserver.Listener) = Unit
|
|
||||||
|
|
||||||
override fun unregister(listener: BackgroundDetectionObserver.Listener) = Unit
|
|
||||||
}
|
|
||||||
|
@ -52,9 +52,9 @@ internal class MatrixWorkerFactory @Inject constructor(private val sessionManage
|
|||||||
): ListenableWorker? {
|
): ListenableWorker? {
|
||||||
Timber.d("MatrixWorkerFactory.createWorker for $workerClassName")
|
Timber.d("MatrixWorkerFactory.createWorker for $workerClassName")
|
||||||
return when (workerClassName) {
|
return when (workerClassName) {
|
||||||
CheckFactoryWorker::class.java.name ->
|
CheckFactoryWorker::class.java.name ->
|
||||||
CheckFactoryWorker(appContext, workerParameters, true)
|
CheckFactoryWorker(appContext, workerParameters, true)
|
||||||
AddPusherWorker::class.java.name ->
|
AddPusherWorker::class.java.name ->
|
||||||
AddPusherWorker(appContext, workerParameters, sessionManager)
|
AddPusherWorker(appContext, workerParameters, sessionManager)
|
||||||
CancelGossipRequestWorker::class.java.name ->
|
CancelGossipRequestWorker::class.java.name ->
|
||||||
CancelGossipRequestWorker(appContext, workerParameters, sessionManager)
|
CancelGossipRequestWorker(appContext, workerParameters, sessionManager)
|
||||||
@ -90,10 +90,15 @@ internal class MatrixWorkerFactory @Inject constructor(private val sessionManage
|
|||||||
* This worker is launched by the factory with the isCreatedByMatrixWorkerFactory flag to true.
|
* This worker is launched by the factory with the isCreatedByMatrixWorkerFactory flag to true.
|
||||||
* If the MatrixWorkerFactory is not set up, it will default to the other constructor and it will throw
|
* If the MatrixWorkerFactory is not set up, it will default to the other constructor and it will throw
|
||||||
*/
|
*/
|
||||||
class CheckFactoryWorker(context: Context, workerParameters: WorkerParameters, private val isCreatedByMatrixWorkerFactory: Boolean) : CoroutineWorker(context, workerParameters) {
|
class CheckFactoryWorker(context: Context,
|
||||||
|
workerParameters: WorkerParameters,
|
||||||
|
private val isCreatedByMatrixWorkerFactory: Boolean) :
|
||||||
|
CoroutineWorker(context, workerParameters) {
|
||||||
|
|
||||||
// Called by WorkManager if there is no MatrixWorkerFactory
|
// Called by WorkManager if there is no MatrixWorkerFactory
|
||||||
constructor(context: Context, workerParameters: WorkerParameters) : this(context, workerParameters, isCreatedByMatrixWorkerFactory = false)
|
constructor(context: Context, workerParameters: WorkerParameters) : this(context,
|
||||||
|
workerParameters,
|
||||||
|
isCreatedByMatrixWorkerFactory = false)
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
return if (!isCreatedByMatrixWorkerFactory) {
|
return if (!isCreatedByMatrixWorkerFactory) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user