From f3453969188102fbe803e09bf0c69cb2082a8dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Wed, 19 Jun 2024 15:56:40 +0200 Subject: [PATCH 01/10] Clean up app initializer infrastructure --- .../io/realm/kotlin/test/mongodb/TestApp.kt | 19 +- .../test/mongodb/util/AppServicesClient.kt | 286 +++++----- .../mongodb/util/KtorTestAppInitializer.kt | 7 +- .../test/mongodb/util/TestAppInitializer.kt | 489 +++++++++--------- .../test/mongodb/common/ApiKeyAuthTests.kt | 4 +- .../mongodb/common/AppConfigurationTests.kt | 11 +- .../kotlin/test/mongodb/common/AppTests.kt | 13 +- .../mongodb/common/AsymmetricSyncTests.kt | 4 +- .../test/mongodb/common/CredentialsTests.kt | 3 +- .../mongodb/common/EmailPasswordAuthTests.kt | 30 +- .../common/FLXProgressListenerTests.kt | 6 +- .../common/FlexibleSyncConfigurationTests.kt | 4 +- .../common/FlexibleSyncIntegrationTests.kt | 4 +- .../test/mongodb/common/FunctionsTests.kt | 38 +- .../test/mongodb/common/GeoSpatialTests.kt | 4 +- .../mongodb/common/HttpLogObfuscatorTests.kt | 45 +- .../common/MutableSubscriptionSetTests.kt | 4 +- .../common/PBSProgressListenerTests.kt | 6 +- .../common/SubscriptionExtensionsTests.kt | 4 +- .../mongodb/common/SubscriptionSetTests.kt | 8 +- .../test/mongodb/common/SubscriptionTests.kt | 3 +- .../common/SyncClientResetIntegrationTests.kt | 17 +- .../test/mongodb/common/SyncClientTests.kt | 3 +- .../test/mongodb/common/SyncConfigTests.kt | 3 +- .../test/mongodb/common/SyncSessionTests.kt | 3 +- .../test/mongodb/common/SyncedRealmTests.kt | 16 +- .../test/mongodb/common/UserProfileTests.kt | 2 + .../kotlin/test/mongodb/common/UserTests.kt | 3 +- .../internal/KtorNetworkTransportTest.kt | 9 +- .../mongodb/common/mongo/MongoClientTests.kt | 4 +- .../common/mongo/MongoCollectionTests.kt | 4 +- .../common/mongo/MongoDatabaseTests.kt | 4 +- .../mongodb/common/nonlatin/NonLatinTests.kt | 3 +- .../kotlin/test/mongodb/jvm/RealmTests.kt | 3 +- 34 files changed, 553 insertions(+), 513 deletions(-) diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/TestApp.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/TestApp.kt index 4af35452e4..fadeaec1f2 100644 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/TestApp.kt +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/TestApp.kt @@ -35,10 +35,8 @@ import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA import io.realm.kotlin.test.mongodb.util.AppAdmin import io.realm.kotlin.test.mongodb.util.AppAdminImpl +import io.realm.kotlin.test.mongodb.util.AppInitializer import io.realm.kotlin.test.mongodb.util.AppServicesClient -import io.realm.kotlin.test.mongodb.util.BaasApp -import io.realm.kotlin.test.mongodb.util.Service -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializeDefault import io.realm.kotlin.test.platform.PlatformUtils import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.use @@ -94,27 +92,23 @@ open class TestApp private constructor( @OptIn(ExperimentalKBsonSerializerApi::class) constructor( testId: String?, - appName: String = TEST_APP_PARTITION, + appInitializer: AppInitializer, dispatcher: CoroutineDispatcher = singleThreadDispatcher("$testId-dispatcher"), builder: (AppConfiguration.Builder) -> AppConfiguration.Builder = { - it.syncRootDirectory(PlatformUtils.createTempDir("$appName-$testId")) + it.syncRootDirectory(PlatformUtils.createTempDir("${appInitializer.name}-$testId")) }, debug: Boolean = false, networkTransport: NetworkTransport? = null, ejson: EJson = EJson, - initialSetup: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit = { app: BaasApp, service: Service -> - initializeDefault(app, service) - } ) : this( dispatcher, build( debug = debug, - appName = appName, + appInitializer = appInitializer, dispatcher = dispatcher, builder = builder, networkTransport = networkTransport, ejson = ejson, - initialSetup = initialSetup ) ) @@ -196,12 +190,11 @@ open class TestApp private constructor( @Suppress("LongParameterList") fun build( debug: Boolean, - appName: String, + appInitializer: AppInitializer, dispatcher: CoroutineDispatcher, builder: (AppConfiguration.Builder) -> AppConfiguration.Builder, networkTransport: NetworkTransport?, ejson: EJson, - initialSetup: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit ): Pair { val appAdmin: AppAdmin = runBlocking(dispatcher) { AppServicesClient.build( @@ -209,7 +202,7 @@ open class TestApp private constructor( debug = debug, dispatcher = dispatcher ).run { - val baasApp = getOrCreateApp(appName, initialSetup) + val baasApp = getOrCreateApp(appInitializer) AppAdminImpl(this, baasApp) } diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/AppServicesClient.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/AppServicesClient.kt index 58b770d1a5..366cb6dfaf 100644 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/AppServicesClient.kt +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/AppServicesClient.kt @@ -40,7 +40,6 @@ import io.realm.kotlin.mongodb.sync.SyncMode import io.realm.kotlin.test.mongodb.SyncServerConfig import io.realm.kotlin.test.mongodb.TEST_APP_CLUSTER_NAME import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA_COUNT -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initialize import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import kotlinx.serialization.InternalSerializationApi @@ -66,6 +65,7 @@ import kotlinx.serialization.json.put import kotlinx.serialization.serializer private const val ADMIN_PATH = "/api/admin/v3.0" +private const val PRIVATE_PATH = "/api/private/v1.0" data class SyncPermissions( val read: Boolean, @@ -113,8 +113,17 @@ data class BaasApp( @SerialName("client_app_id") val clientAppId: String, val name: String, @SerialName("domain_id") val domainId: String, - @SerialName("group_id") val groupId: String -) + @SerialName("group_id") val groupId: String, + + @Transient private val _client: AppServicesClient? = null +) { + val client: AppServicesClient + get() = _client ?: TODO("App should be copy'ed with _client set to the AppServicesClient that retrieved it") + val url: String + get() = client.baseUrl + ADMIN_PATH + "/groups/${this.groupId}/apps/${this._id}" + val privateUrl: String + get() = client.baseUrl + PRIVATE_PATH + "/groups/${this.groupId}/apps/${this._id}" +} /** * Client to interact with App Services Server. It allows to create Applications and tweak their @@ -122,145 +131,34 @@ data class BaasApp( */ class AppServicesClient( val baseUrl: String, - private val groupUrl: String, - private val httpClient: HttpClient, + private val groupId: String, + internal val httpClient: HttpClient, val dispatcher: CoroutineDispatcher, ) { - companion object { - // Default serializer fails with - // InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap - // on native. Have tried the various workarounds from - // https://github.com/Kotlin/kotlinx.serialization/issues/1450 - // but only one that works is manual invoking the deserializer - @OptIn(InternalSerializationApi::class) - private suspend inline fun HttpClient.typedRequest( - method: HttpMethod, - url: String, - crossinline block: HttpRequestBuilder.() -> Unit = {} - ): T { - val response: HttpResponse = this@typedRequest.request(url) { - this.method = method - this.apply(block) - } - if (!response.status.isSuccess()) { - throw IllegalStateException("Http request failed: $url. ${response.status}: ${response.bodyAsText()}") - } - return response.bodyAsText() - .let { - Json { ignoreUnknownKeys = true }.decodeFromString( - T::class.serializer(), - it - ) - } - } - - // Default serializer fails with - // InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap - // on native. Have tried the various workarounds from - // https://github.com/Kotlin/kotlinx.serialization/issues/1450 - // but only one that works is manual invoking the deserializer - @OptIn(InternalSerializationApi::class) - private suspend inline fun HttpClient.typedListRequest( - method: HttpMethod, - url: String, - crossinline block: HttpRequestBuilder.() -> Unit = {} - ): List { - return this@typedListRequest.request(url) { - this.method = method - this.apply(block) - }.bodyAsText() - .let { - Json { ignoreUnknownKeys = true }.decodeFromString( - ListSerializer(T::class.serializer()), - it - ) - } - } - - suspend fun build( - debug: Boolean, - baseUrl: String, - dispatcher: CoroutineDispatcher, - ): AppServicesClient { - val adminUrl = baseUrl + ADMIN_PATH - // Work around issues on Native with the Ktor client being created and used - // on different threads. - // Log in using unauthorized client - val unauthorizedClient = defaultClient("realm-baas-unauthorized", debug) - - var loginMethod: String = "local-userpass" - var json: Map = mapOf("username" to SyncServerConfig.email, "password" to SyncServerConfig.password) - if (SyncServerConfig.publicApiKey.isNotEmpty()) { - loginMethod = "mongodb-cloud" - json = mapOf("username" to SyncServerConfig.publicApiKey, "apiKey" to SyncServerConfig.privateApiKey) - } - val loginResponse = unauthorizedClient.typedRequest( - HttpMethod.Post, - "$adminUrl/auth/providers/$loginMethod/login" - ) { - contentType(ContentType.Application.Json) - setBody(json) - } - - // Setup authorized client for the rest of the requests - val accessToken = loginResponse.access_token - unauthorizedClient.close() - - val httpClient = defaultClient("realm-baas-authorized", debug) { - defaultRequest { - headers { - append("Authorization", "Bearer $accessToken") - } - } - install(ContentNegotiation) { - json( - Json { - prettyPrint = true - isLenient = true - } - ) - } - install(Logging) { - // Set to LogLevel.ALL to debug Admin API requests. All relevant - // data for each request/response will be console or LogCat. - level = LogLevel.INFO - } - } - - // Collect app group id - val groupId = httpClient.typedRequest(Get, "$adminUrl/auth/profile") - .roles - .first() - .group_id - return AppServicesClient( - baseUrl, - "$adminUrl/groups/$groupId", - httpClient, - dispatcher - ) - } - } + val groupUrl: String + get() = baseUrl + ADMIN_PATH + "/groups/$groupId" fun closeClient() { httpClient.close() } - suspend fun getOrCreateApp( - appName: String, - initializer: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit - ): BaasApp = - getApp(appName) ?: createApp(appName) { - initialize(this, initializer) + suspend fun getOrCreateApp(appInitializer: AppInitializer): BaasApp { + val app = getApp(appInitializer.name) + return app ?: createApp(appInitializer.name) { + appInitializer.initialize(this@AppServicesClient, this) } + } - private suspend fun getApp(appName: String): BaasApp? = - withContext(dispatcher) { + private suspend fun getApp(appName: String): BaasApp? { + val withContext = withContext(dispatcher) { httpClient.typedListRequest(Get, "$groupUrl/apps") .firstOrNull { it.name == appName - } + }?.copy(_client = this@AppServicesClient) } + return withContext + } private suspend fun createApp( appName: String, @@ -273,14 +171,23 @@ class AppServicesClient( httpClient.typedRequest(Post, "$groupUrl/apps") { setBody(Json.parseToJsonElement("""{"name": $appName}""")) contentType(ContentType.Application.Json) - }.apply { + }.copy(_client = this@AppServicesClient).apply { initializer(this) } } } - val BaasApp.url: String - get() = "$groupUrl/apps/${this._id}" + suspend fun BaasApp.toggleFeatures(features: Set, enable: Boolean) { + withContext(dispatcher) { + httpClient.typedRequest( + Post, + "$privateUrl/features" + ) { + setBody(Json.parseToJsonElement("""{ "action": "${if (enable) "enable" else "disable"}", "feature_flags": [ ${features.joinToString { "\"$it\"" }} ] }""")) + contentType(ContentType.Application.Json) + } + } + } suspend fun BaasApp.addFunction(function: Function): Function = withContext(dispatcher) { @@ -475,7 +382,7 @@ class AppServicesClient( .first { val type = if (TEST_APP_CLUSTER_NAME.isEmpty()) "mongodb" else "mongodb-atlas" it.type == type - } + }.copy(app = this@mongodbService) } } @@ -715,4 +622,119 @@ class AppServicesClient( } } } + companion object { + suspend fun build( + debug: Boolean, + baseUrl: String, + dispatcher: CoroutineDispatcher, + ): AppServicesClient { + val adminUrl = baseUrl + ADMIN_PATH + // Work around issues on Native with the Ktor client being created and used + // on different threads. + // Log in using unauthorized client + val unauthorizedClient = defaultClient("realm-baas-unauthorized", debug) + + var loginMethod: String = "local-userpass" + var json: Map = mapOf("username" to SyncServerConfig.email, "password" to SyncServerConfig.password) + if (SyncServerConfig.publicApiKey.isNotEmpty()) { + loginMethod = "mongodb-cloud" + json = mapOf("username" to SyncServerConfig.publicApiKey, "apiKey" to SyncServerConfig.privateApiKey) + } + val loginResponse = unauthorizedClient.typedRequest( + HttpMethod.Post, + "$adminUrl/auth/providers/$loginMethod/login" + ) { + contentType(ContentType.Application.Json) + setBody(json) + } + + // Setup authorized client for the rest of the requests + val accessToken = loginResponse.access_token + unauthorizedClient.close() + + val httpClient = defaultClient("realm-baas-authorized", debug) { + defaultRequest { + headers { + append("Authorization", "Bearer $accessToken") + } + } + install(ContentNegotiation) { + json( + Json { + prettyPrint = true + isLenient = true + } + ) + } + install(Logging) { + // Set to LogLevel.ALL to debug Admin API requests. All relevant + // data for each request/response will be console or LogCat. + level = LogLevel.ALL + } + } + + // Collect app group id + val groupId = httpClient.typedRequest(Get, "$adminUrl/auth/profile") + .roles + .first() + .group_id ?: "null" + + return AppServicesClient( + baseUrl, + groupId, + httpClient, + dispatcher + ) + } + } +} + +// Default serializer fails with +// InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap +// on native. Have tried the various workarounds from +// https://github.com/Kotlin/kotlinx.serialization/issues/1450 +// but only one that works is manual invoking the deserializer +@OptIn(InternalSerializationApi::class) +private suspend inline fun HttpClient.typedRequest( + method: HttpMethod, + url: String, + crossinline block: HttpRequestBuilder.() -> Unit = {} +): T { + val response: HttpResponse = this@typedRequest.request(url) { + this.method = method + this.apply(block) + } + if (!response.status.isSuccess()) { + throw IllegalStateException("Http request failed: $url. ${response.status}: ${response.bodyAsText()}") + } + return response.bodyAsText() + .let { + Json { ignoreUnknownKeys = true }.decodeFromString( + T::class.serializer(), + it + ) + } +} + +// Default serializer fails with +// InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap +// on native. Have tried the various workarounds from +// https://github.com/Kotlin/kotlinx.serialization/issues/1450 +// but only one that works is manual invoking the deserializer +@OptIn(InternalSerializationApi::class) +private suspend inline fun HttpClient.typedListRequest( + method: HttpMethod, + url: String, + crossinline block: HttpRequestBuilder.() -> Unit = {} +): List { + return this@typedListRequest.request(url) { + this.method = method + this.apply(block) + }.bodyAsText() + .let { + Json { ignoreUnknownKeys = true }.decodeFromString( + ListSerializer(T::class.serializer()), + it + ) + } } diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt index 7abcb1333a..3511c6914d 100644 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt @@ -17,7 +17,10 @@ package io.realm.kotlin.test.mongodb.util import io.ktor.http.HttpMethod -object KtorTestAppInitializer { +object KtorTestAppInitializer : AppInitializer { + override suspend fun initialize(client: AppServicesClient, app: BaasApp) { + client.initialize(app, TEST_METHODS) + } // Setups the app with the functions and https endpoints required to run the KtorNetworkTransportTests suspend fun AppServicesClient.initialize(app: BaasApp, methods: List) = @@ -68,4 +71,6 @@ object KtorTestAppInitializer { ) } } + + override val name: String = "ktor-test-app" } diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt index 60d9dfb223..b017e0539f 100644 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt @@ -18,29 +18,116 @@ package io.realm.kotlin.test.mongodb.util import io.realm.kotlin.test.mongodb.TEST_APP_CLUSTER_NAME import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json -object TestAppInitializer { - // Setups a test app - suspend fun AppServicesClient.initializeDefault(app: BaasApp, service: Service) { - addEmailProvider(app) +interface AppInitializer { + val name: String + suspend fun initialize(client: AppServicesClient, app: BaasApp) +} + +open class BaseAppInitializer( + override val name: String, + val block: (suspend AppServicesClient.(app: BaasApp) -> Unit)? = null, +) : AppInitializer { + + override suspend fun initialize(client: AppServicesClient, app: BaasApp) { + with(client) { + with(app) { + addFunction(insertDocument) + addFunction(queryDocument) + addFunction(deleteDocument) + addFunction(countDocuments) + + val testAuthFuncId = addFunction(testAuthFunc)._id + addAuthProvider( + """ + { + "type": "custom-function", + "config": { + "authFunctionId": "$testAuthFuncId", + "authFunctionName": "${testAuthFunc.name}" + } + } + """.trimIndent() + ) + + addAuthProvider("""{"type": "anon-user"}""") - when (app.name) { - TEST_APP_PARTITION -> initializePartitionSync(app, service) - TEST_APP_FLEX -> initializeFlexibleSync(app, service) + // Enable 'API-KEY' by updating it. It exists by default in the server so we cannot add. + getAuthProvider("api-key").run { + enable(true) + } + + val (type: String, config: String) = if (TEST_APP_CLUSTER_NAME.isEmpty()) { + "mongodb" to """{ "uri": "mongodb://localhost:26000" }""" + } else { + "mongodb-atlas" to """{ "clusterName": "$TEST_APP_CLUSTER_NAME" }""" + } + addService( + """ + { + "name": "BackingDB", + "type": "$type", + "config": $config + } + """.trimIndent() + ).let { service: Service -> + val dbName = app.clientAppId + service.addDefaultRule( + """ + { + "roles": [{ + "name": "defaultRole", + "apply_when": {}, + "document_filters": { + "read": true, + "write": true + }, + "write": true, + "read": true, + "insert": true, + "delete": true + }] + } + """.trimIndent() + ) + + app.setCustomUserData( + """ + { + "mongo_service_id": ${service._id}, + "enabled": true, + "database_name": "$dbName", + "collection_name": "UserData", + "user_id_field": "user_id" + } + """.trimIndent() + ) + } + with(client) { + block?.invoke(this, app) + } + app.setDevelopmentMode(true) + addEmailProvider(app) + } } } +} + +object DefaultPartitionBasedAppInitializer : + BaseAppInitializer(TEST_APP_PARTITION, { initializePartitionSync(it) }) + +object DefaultFlexibleSyncAppInitializer : + BaseAppInitializer(TEST_APP_FLEX, { initializeFlexibleSync(it) }) - @Suppress("LongMethod") - suspend fun AppServicesClient.initializeFlexibleSync( - app: BaasApp, - service: Service, - recoveryDisabled: Boolean = false // TODO - ) { - val databaseName = app.clientAppId - service.setSyncConfig( - """ +@Suppress("LongMethod") +suspend fun AppServicesClient.initializeFlexibleSync( + app: BaasApp, + recoveryDisabled: Boolean = false, // TODO +) { + val databaseName = app.clientAppId + app.mongodbService.setSyncConfig( + """ { "flexible_sync": { "state": "enabled", @@ -52,23 +139,22 @@ object TestAppInitializer { ] } } - """.trimIndent() - ) - } + """.trimIndent() + ) +} - @Suppress("LongMethod") - suspend fun AppServicesClient.initializePartitionSync( - app: BaasApp, - service: Service, - recoveryDisabled: Boolean = false // TODO - ) { - val databaseName = app.clientAppId +@Suppress("LongMethod") +suspend fun AppServicesClient.initializePartitionSync( + app: BaasApp, + recoveryDisabled: Boolean = false, // TODO +) { + val databaseName = app.clientAppId - app.addFunction(canReadPartition) - app.addFunction(canWritePartition) + app.addFunction(canReadPartition) + app.addFunction(canWritePartition) - service.setSyncConfig( - """ + app.mongodbService.setSyncConfig( + """ { "sync": { "state": "enabled", @@ -102,11 +188,11 @@ object TestAppInitializer { } } } - """.trimIndent() - ) + """.trimIndent() + ) - app.addSchema( - """ + app.addSchema( + """ { "metadata": { "data_source": "BackingDB", @@ -134,11 +220,11 @@ object TestAppInitializer { "title": "SyncDog" } } - """.trimIndent() - ) + """.trimIndent() + ) - app.addSchema( - """ + app.addSchema( + """ { "metadata": { "data_source": "BackingDB", @@ -185,20 +271,20 @@ object TestAppInitializer { "title": "SyncPerson" } } - """.trimIndent() - ) - } + """.trimIndent() + ) +} - suspend fun AppServicesClient.addEmailProvider( - app: BaasApp, - autoConfirm: Boolean = true, - runConfirmationFunction: Boolean = false - ) = with(app) { - val confirmFuncId = addFunction(confirmFunc)._id - val resetFuncId = addFunction(resetFunc)._id +suspend fun AppServicesClient.addEmailProvider( + app: BaasApp, + autoConfirm: Boolean = true, + runConfirmationFunction: Boolean = false, +) = with(app) { + val confirmFuncId = addFunction(confirmFunc)._id + val resetFuncId = addFunction(resetFunc)._id - addAuthProvider( - """ + addAuthProvider( + """ { "type": "local-userpass", "config": { @@ -214,95 +300,14 @@ object TestAppInitializer { "runResetFunction": false } } - """.trimIndent() - ) - } - - suspend fun AppServicesClient.initialize( - app: BaasApp, - block: suspend AppServicesClient.(app: BaasApp, service: Service) -> Unit - ) = with(app) { - addFunction(insertDocument) - addFunction(queryDocument) - addFunction(deleteDocument) - addFunction(countDocuments) - - val testAuthFuncId = addFunction(testAuthFunc)._id - addAuthProvider( - """ - { - "type": "custom-function", - "config": { - "authFunctionId": "$testAuthFuncId", - "authFunctionName": "${testAuthFunc.name}" - } - } - """.trimIndent() - ) - - addAuthProvider("""{"type": "anon-user"}""") - - // Enable 'API-KEY' by updating it. It exists by default in the server so we cannot add. - getAuthProvider("api-key").run { - enable(true) - } - - val (type: String, config: String) = if (TEST_APP_CLUSTER_NAME.isEmpty()) { - "mongodb" to """{ "uri": "mongodb://localhost:26000" }""" - } else { - "mongodb-atlas" to """{ "clusterName": "$TEST_APP_CLUSTER_NAME" }""" - } - addService( - """ - { - "name": "BackingDB", - "type": "$type", - "config": $config - } - """.trimIndent() - ).let { service: Service -> - val dbName = app.clientAppId - service.addDefaultRule( - """ - { - "roles": [{ - "name": "defaultRole", - "apply_when": {}, - "document_filters": { - "read": true, - "write": true - }, - "write": true, - "read": true, - "insert": true, - "delete": true - }] - } - """.trimIndent() - ) - - app.setCustomUserData( - """ - { - "mongo_service_id": ${service._id}, - "enabled": true, - "database_name": "$dbName", - "collection_name": "UserData", - "user_id_field": "user_id" - } - """.trimIndent() - ) - - block(app, service) - } - - setDevelopmentMode(true) - } + """.trimIndent() + ) +} - private val insertDocument = Function( - name = "insertDocument", - source = - """ +private val insertDocument = Function( + name = "insertDocument", + source = + """ exports = function (service, db, collection, document) { const mongodb = context.services.get(service); const result = mongodb @@ -313,13 +318,13 @@ object TestAppInitializer { return result; } - """.trimIndent() - ) + """.trimIndent() +) - private val deleteDocument = Function( - name = "deleteDocument", - source = - """ +private val deleteDocument = Function( + name = "deleteDocument", + source = + """ exports = function (service, db, collection, query) { const mongodb = context.services.get(service); const result = mongodb @@ -330,13 +335,13 @@ object TestAppInitializer { return result; } - """.trimIndent() - ) + """.trimIndent() +) - private val queryDocument = Function( - name = "queryDocument", - source = - """ +private val queryDocument = Function( + name = "queryDocument", + source = + """ exports = function (service, db, collection, query) { const mongodb = context.services.get(service); const result = mongodb @@ -346,14 +351,13 @@ object TestAppInitializer { return result; } - - """.trimIndent() - ) + """.trimIndent() +) - private val countDocuments = Function( - name = "countDocuments", - source = - """ +private val countDocuments = Function( + name = "countDocuments", + source = + """ exports = function (service, db, collection) { const mongodb = context.services.get(service); const result = mongodb @@ -363,13 +367,13 @@ object TestAppInitializer { return { value: result }; } - """.trimIndent() - ) + """.trimIndent() +) - private val testAuthFunc = Function( - name = "testAuthFunc", - source = - """ +private val testAuthFunc = Function( + name = "testAuthFunc", + source = + """ exports = ({mail, id}) => { // Auth function will fail for emails with a domain different to @10gen.com // or with id lower than 666 @@ -380,14 +384,13 @@ object TestAppInitializer { return mail; } } - - """.trimIndent() - ) + """.trimIndent() +) - private val confirmFunc = Function( - name = "confirmFunc", - source = - """ +private val confirmFunc = Function( + name = "confirmFunc", + source = + """ exports = async ({ token, tokenId, username }) => { // process the confirm token, tokenId and username @@ -413,14 +416,13 @@ object TestAppInitializer { return { status: 'fail' }; } } - - """.trimIndent() - ) + """.trimIndent() +) - private val resetFunc = Function( - name = "resetFunc", - source = - """ +private val resetFunc = Function( + name = "resetFunc", + source = + """ exports = ({ token, tokenId, username, password }, customParam1, customParam2) => { if (customParam1 != "say-the-magic-word" || customParam2 != 42) { return { status: 'fail' }; @@ -428,14 +430,13 @@ object TestAppInitializer { return { status: 'success' }; } } - - """.trimIndent() - ) + """.trimIndent() +) - private val canReadPartition = Function( - name = "canReadPartition", - source = - """ +private val canReadPartition = Function( + name = "canReadPartition", + source = + """ /** * Users with an email that contains `_noread_` do not have read access, * all others do. @@ -448,90 +449,84 @@ object TestAppInitializer { return true; } } - - """.trimIndent() - ) + """.trimIndent() +) - private val canWritePartition = Function( +private val canWritePartition = + Function( name = "canWritePartition", source = """ - /** - * Users with an email that contains `_nowrite_` do not have write access, - * all others do. - */ - exports = async (partition) => { - const email = context.user.data.email; - if (email != undefined) { - return(!email.includes("_nowrite_")); - } else { - return true; - } - } - + /** + * Users with an email that contains `_nowrite_` do not have write access, + * all others do. + */ + exports = async (partition) => { + const email = context.user.data.email; + if (email != undefined) { + return(!email.includes("_nowrite_")); + } else { + return true; + } + } """.trimIndent() ) - val FIRST_ARG_FUNCTION = Function( - name = "firstArg", - source = - """ +val FIRST_ARG_FUNCTION = Function( + name = "firstArg", + source = + """ exports = function(arg){ // Returns first argument return arg }; - - """.trimIndent() - ) + """.trimIndent() +) - val SUM_FUNCTION = Function( - name = "sum", - source = - """ +val SUM_FUNCTION = Function( + name = "sum", + source = + """ exports = function(...args) { return parseInt(args.reduce((a,b) => a + b, 0)); }; - - """.trimIndent() - ) + """.trimIndent() +) - val NULL_FUNCTION = Function( - name = "null", - source = - """ +val NULL_FUNCTION = Function( + name = "null", + source = + """ exports = function(arg){ return null; }; - - """.trimIndent() - ) + """.trimIndent() +) - val ERROR_FUNCTION = Function( - name = "error", - source = - """ +val ERROR_FUNCTION = Function( + name = "error", + source = + """ exports = function(arg){ return unknown; }; - - """.trimIndent() - ) + """.trimIndent() +) - val VOID_FUNCTION = Function( - name = "void", - source = - """ +val VOID_FUNCTION = Function( + name = "void", + source = + """ exports = function(arg){ return void(0); }; - - """.trimIndent() - ) + """.trimIndent() +) - val AUTHORIZED_ONLY_FUNCTION = Function( - name = "authorizedOnly", - source = - """ +val AUTHORIZED_ONLY_FUNCTION = Function( + name = "authorizedOnly", + source = + """ exports = function(arg){ /* Accessing application's values: @@ -548,10 +543,9 @@ object TestAppInitializer { */ return {arg: context.user}; }; - - """.trimIndent(), - canEvaluate = Json.decodeFromString( - """ + """.trimIndent(), + canEvaluate = Json.decodeFromString( + """ { "%%user.data.email": { "%in": [ @@ -559,7 +553,6 @@ object TestAppInitializer { ] } } - """.trimIndent() - ) + """.trimIndent() ) -} +) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/ApiKeyAuthTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/ApiKeyAuthTests.kt index 6b4e3f0add..0c6a6e30d7 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/ApiKeyAuthTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/ApiKeyAuthTests.kt @@ -19,9 +19,9 @@ import io.realm.kotlin.internal.platform.runBlocking import io.realm.kotlin.mongodb.User import io.realm.kotlin.mongodb.auth.ApiKeyAuth import io.realm.kotlin.mongodb.exceptions.ServiceException -import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper import org.mongodb.kbson.BsonObjectId import kotlin.test.AfterTest @@ -50,7 +50,7 @@ class ApiKeyAuthTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_PARTITION) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) user = app.createUserAndLogin() provider = user.apiKeyAuth } diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppConfigurationTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppConfigurationTests.kt index 530ceb7ced..7747c7b0fe 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppConfigurationTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppConfigurationTests.kt @@ -34,6 +34,7 @@ import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.use +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.platform.PlatformUtils import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper @@ -167,9 +168,11 @@ class AppConfigurationTests { @Test fun syncRootDirectory_appendDirectoryToPath() = runBlocking { val expectedRoot = pathOf(appFilesDirectory(), "myCustomDir") - TestApp("syncRootDirectory_appendDirectoryToPath", builder = { - it.syncRootDirectory(expectedRoot) - }).use { app -> + TestApp( + "syncRootDirectory_appendDirectoryToPath", + DefaultPartitionBasedAppInitializer, + builder = { it.syncRootDirectory(expectedRoot) } + ).use { app -> val (email, password) = TestHelper.randomEmail() to "password1234" val user = app.createUserAndLogIn(email, password) assertEquals(expectedRoot, app.configuration.syncRootDirectory) @@ -387,6 +390,8 @@ class AppConfigurationTests { fun customHeadersTest() = runBlocking { TestApp( "customHeadersTest", + DefaultPartitionBasedAppInitializer, + debug = true, builder = { builder -> builder.customRequestHeaders { put(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppTests.kt index 06ae7fc104..c9f2158572 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AppTests.kt @@ -37,12 +37,13 @@ import io.realm.kotlin.mongodb.exceptions.AuthException import io.realm.kotlin.mongodb.exceptions.ServiceException import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.test.mongodb.SyncServerConfig -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.use +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.TestHelper.randomEmail @@ -68,7 +69,7 @@ class AppTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) } @AfterTest @@ -380,7 +381,7 @@ class AppTests { val key = TestHelper.getRandomKey() TestApp( "encryptedMetadataRealm", - appName = TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it .encryptionKey(key) @@ -417,7 +418,7 @@ class AppTests { val correctKey = TestHelper.getRandomKey() TestApp( "encryptedMetadataRealm_openWithWrongKeyThrows", - appName = TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it .encryptionKey(correctKey) @@ -455,7 +456,7 @@ class AppTests { // Create new test app with a random encryption key TestApp( "encryptedMetadataRealm_openWithoutKeyThrows", - appName = TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it .encryptionKey(TestHelper.getRandomKey()) @@ -496,6 +497,7 @@ class AppTests { fun changeBaseUrl() { TestApp( testId = "changeBaseUrl", + DefaultPartitionBasedAppInitializer, builder = { builder -> // We create a test app that points to the default base url // this app is not going to be validated yet. @@ -521,6 +523,7 @@ class AppTests { fun changeBaseUrl_null() { TestApp( testId = "changeBaseUrl", + DefaultPartitionBasedAppInitializer, ).use { testApp -> assertEquals(SyncServerConfig.url, testApp.baseUrl) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AsymmetricSyncTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AsymmetricSyncTests.kt index 1e2675c481..fbdddadf81 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AsymmetricSyncTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/AsymmetricSyncTests.kt @@ -30,10 +30,10 @@ import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.syncSession import io.realm.kotlin.schema.RealmClassKind import io.realm.kotlin.test.StandaloneDynamicMutableRealm -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.use import kotlinx.atomicfu.atomic @@ -56,7 +56,7 @@ class AsymmetricSyncTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" val user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt index 53f3bf8fb8..75e1e3f828 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/CredentialsTests.kt @@ -35,6 +35,7 @@ import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper import kotlinx.serialization.Serializable import kotlin.test.AfterTest @@ -60,7 +61,7 @@ class CredentialsTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) } @AfterTest diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/EmailPasswordAuthTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/EmailPasswordAuthTests.kt index 40ee4d0ac1..39f123121c 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/EmailPasswordAuthTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/EmailPasswordAuthTests.kt @@ -10,13 +10,13 @@ import io.realm.kotlin.mongodb.exceptions.ServiceException import io.realm.kotlin.mongodb.exceptions.UserAlreadyConfirmedException import io.realm.kotlin.mongodb.exceptions.UserAlreadyExistsException import io.realm.kotlin.mongodb.exceptions.UserNotFoundException -import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.syncServerAppName import io.realm.kotlin.test.mongodb.util.BaasApp -import io.realm.kotlin.test.mongodb.util.Service -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.addEmailProvider +import io.realm.kotlin.test.mongodb.util.BaseAppInitializer +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer +import io.realm.kotlin.test.mongodb.util.addEmailProvider import io.realm.kotlin.test.util.TestHelper import kotlin.test.AfterTest import kotlin.test.BeforeTest @@ -32,7 +32,7 @@ class EmailPasswordAuthWithAutoConfirmTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_PARTITION) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) } @AfterTest @@ -243,9 +243,13 @@ class EmailPasswordAuthWithEmailConfirmTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = syncServerAppName("em-cnfrm"), initialSetup = { app: BaasApp, service: Service -> - addEmailProvider(app, autoConfirm = false) - }) + app = TestApp( + this::class.simpleName, + object : BaseAppInitializer( + syncServerAppName("em-cnfrm"), + { app: BaasApp -> addEmailProvider(app, autoConfirm = false) } + ) {} + ) } @AfterTest @@ -281,9 +285,15 @@ class EmailPasswordAuthWithCustomFunctionTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = syncServerAppName("em-cstm"), initialSetup = { app: BaasApp, service: Service -> - addEmailProvider(app, autoConfirm = false, runConfirmationFunction = true) - }) + app = TestApp( + this::class.simpleName, + object : BaseAppInitializer( + syncServerAppName("em-cstm"), + { app -> + addEmailProvider(app, autoConfirm = false, runConfirmationFunction = true) + } + ) {} + ) } @AfterTest diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FLXProgressListenerTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FLXProgressListenerTests.kt index 9fe4307aa6..9c67b39196 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FLXProgressListenerTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FLXProgressListenerTests.kt @@ -26,10 +26,10 @@ import io.realm.kotlin.mongodb.sync.Progress import io.realm.kotlin.mongodb.sync.ProgressMode import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.syncSession -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.use +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.receiveOrFail import io.realm.kotlin.test.util.use @@ -66,7 +66,7 @@ class FLXProgressListenerTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) partitionValue = org.mongodb.kbson.ObjectId().toString() } @@ -233,7 +233,7 @@ class FLXProgressListenerTests { @Test fun completesOnClose() = runBlocking { val channel = TestChannel(capacity = 5, onBufferOverflow = BufferOverflow.DROP_OLDEST, failIfBufferIsEmptyOnCancel = false) - TestApp("completesOnClose", TEST_APP_FLEX).use { app -> + TestApp("completesOnClose", DefaultFlexibleSyncAppInitializer).use { app -> val user = app.createUserAndLogIn() val realm = Realm.open(createSyncConfig(user)) try { diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncConfigurationTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncConfigurationTests.kt index be13d1f51f..337a520fae 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncConfigurationTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncConfigurationTests.kt @@ -24,10 +24,10 @@ import io.realm.kotlin.mongodb.User import io.realm.kotlin.mongodb.sync.InitialSubscriptionsCallback import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.sync.SyncMode -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestHelper import kotlinx.atomicfu.atomic import kotlin.test.AfterTest @@ -47,7 +47,7 @@ class FlexibleSyncConfigurationTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" val user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncIntegrationTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncIntegrationTests.kt index 640c777eee..6951cab536 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncIntegrationTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FlexibleSyncIntegrationTests.kt @@ -29,11 +29,11 @@ import io.realm.kotlin.mongodb.subscriptions import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.sync.SyncSession import io.realm.kotlin.mongodb.syncSession -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.common.utils.waitForSynchronizationOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.receiveOrFail @@ -63,7 +63,7 @@ class FlexibleSyncIntegrationTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt index 747b51c812..70bfdc3ed6 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt @@ -40,15 +40,13 @@ import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.syncServerAppName -import io.realm.kotlin.test.mongodb.util.BaasApp -import io.realm.kotlin.test.mongodb.util.Service -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.AUTHORIZED_ONLY_FUNCTION -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.ERROR_FUNCTION -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.FIRST_ARG_FUNCTION -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.NULL_FUNCTION -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.SUM_FUNCTION -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.VOID_FUNCTION -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializeDefault +import io.realm.kotlin.test.mongodb.util.AUTHORIZED_ONLY_FUNCTION +import io.realm.kotlin.test.mongodb.util.BaseAppInitializer +import io.realm.kotlin.test.mongodb.util.ERROR_FUNCTION +import io.realm.kotlin.test.mongodb.util.FIRST_ARG_FUNCTION +import io.realm.kotlin.test.mongodb.util.NULL_FUNCTION +import io.realm.kotlin.test.mongodb.util.SUM_FUNCTION +import io.realm.kotlin.test.mongodb.util.VOID_FUNCTION import io.realm.kotlin.test.util.TypeDescriptor import io.realm.kotlin.types.MutableRealmInt import io.realm.kotlin.types.RealmAny @@ -201,7 +199,17 @@ class FunctionsTests { fun setup() { app = TestApp( FunctionsTests::class.simpleName, - syncServerAppName("funcs"), + object : BaseAppInitializer( + syncServerAppName("funcs"), + { + it.addFunction(FIRST_ARG_FUNCTION) + it.addFunction(NULL_FUNCTION) + it.addFunction(SUM_FUNCTION) + it.addFunction(ERROR_FUNCTION) + it.addFunction(VOID_FUNCTION) + it.addFunction(AUTHORIZED_ONLY_FUNCTION) + } + ) {}, ejson = EJson( serializersModule = SerializersModule { polymorphic(RealmObject::class) { @@ -209,15 +217,7 @@ class FunctionsTests { } } ) - ) { app: BaasApp, service: Service -> - initializeDefault(app, service) - app.addFunction(FIRST_ARG_FUNCTION) - app.addFunction(NULL_FUNCTION) - app.addFunction(SUM_FUNCTION) - app.addFunction(ERROR_FUNCTION) - app.addFunction(VOID_FUNCTION) - app.addFunction(AUTHORIZED_ONLY_FUNCTION) - } + ) anonUser = runBlocking { app.login(Credentials.anonymous()) } diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/GeoSpatialTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/GeoSpatialTests.kt index 1cdbe71ff3..58c2943aab 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/GeoSpatialTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/GeoSpatialTests.kt @@ -25,9 +25,9 @@ import io.realm.kotlin.internal.platform.runBlocking import io.realm.kotlin.mongodb.User import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.syncSession -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.use import io.realm.kotlin.types.geo.Distance @@ -49,7 +49,7 @@ class GeoSpatialTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) } @AfterTest diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt index f72eba9784..4f9558acc5 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt @@ -29,8 +29,10 @@ import io.realm.kotlin.mongodb.ext.call import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.CustomLogCollector import io.realm.kotlin.test.mongodb.syncServerAppName -import io.realm.kotlin.test.mongodb.util.TestAppInitializer -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializeDefault +import io.realm.kotlin.test.mongodb.util.BaseAppInitializer +import io.realm.kotlin.test.mongodb.util.FIRST_ARG_FUNCTION +import io.realm.kotlin.test.mongodb.util.NULL_FUNCTION +import io.realm.kotlin.test.mongodb.util.SUM_FUNCTION import io.realm.kotlin.test.util.receiveOrFail import kotlinx.coroutines.CancellationException import kotlinx.coroutines.async @@ -122,13 +124,11 @@ class HttpLogObfuscatorTests { private fun initApp(): TestApp { return TestApp( this::class.simpleName, - appName = syncServerAppName("obfsctr"), - initialSetup = { app, service -> - initializeDefault(app, service) - app.addFunction(TestAppInitializer.FIRST_ARG_FUNCTION) - app.addFunction(TestAppInitializer.SUM_FUNCTION) - app.addFunction(TestAppInitializer.NULL_FUNCTION) - } + object : BaseAppInitializer(syncServerAppName("obfsctr"), { + it.addFunction(FIRST_ARG_FUNCTION) + it.addFunction(SUM_FUNCTION) + it.addFunction(NULL_FUNCTION) + }) {} ) } @@ -148,14 +148,15 @@ class HttpLogObfuscatorTests { RealmLog.add(logger) app = TestApp( "nullObfuscator", - appName = syncServerAppName("null-obf"), + object : BaseAppInitializer( + syncServerAppName("null-obf"), + { + it.addFunction(FIRST_ARG_FUNCTION) + it.addFunction(SUM_FUNCTION) + it.addFunction(NULL_FUNCTION) + } + ) {}, builder = { it.httpLogObfuscator(null) }, - initialSetup = { app, service -> - initializeDefault(app, service) - app.addFunction(TestAppInitializer.FIRST_ARG_FUNCTION) - app.addFunction(TestAppInitializer.SUM_FUNCTION) - app.addFunction(TestAppInitializer.NULL_FUNCTION) - } ) // Create user and log in @@ -190,9 +191,9 @@ class HttpLogObfuscatorTests { // Calling functions with arguments results in these not being obfuscated with(user.functions) { - call(TestAppInitializer.FIRST_ARG_FUNCTION.name, 42.0) - call(TestAppInitializer.SUM_FUNCTION.name, 42.0, 1.0) - call(TestAppInitializer.NULL_FUNCTION.name) + call(FIRST_ARG_FUNCTION.name, 42.0) + call(SUM_FUNCTION.name, 42.0, 1.0) + call(NULL_FUNCTION.name) } // Verify that none of the logs are obfuscated @@ -315,9 +316,9 @@ class HttpLogObfuscatorTests { async { with(user.functions) { - call(TestAppInitializer.FIRST_ARG_FUNCTION.name, 42.0) - call(TestAppInitializer.SUM_FUNCTION.name, 42.0, 1.0) - call(TestAppInitializer.NULL_FUNCTION.name) + call(FIRST_ARG_FUNCTION.name, 42.0) + call(SUM_FUNCTION.name, 42.0, 1.0) + call(NULL_FUNCTION.name) } } // 1st custom function call - request (obfuscate arguments) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/MutableSubscriptionSetTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/MutableSubscriptionSetTests.kt index 248aa3e7f0..9e5f9524a0 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/MutableSubscriptionSetTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/MutableSubscriptionSetTests.kt @@ -27,10 +27,10 @@ import io.realm.kotlin.mongodb.sync.SubscriptionSet import io.realm.kotlin.mongodb.sync.SubscriptionSetState import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.syncSession -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.toRealmInstant import io.realm.kotlin.test.util.use @@ -57,7 +57,7 @@ class MutableSubscriptionSetTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" val user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/PBSProgressListenerTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/PBSProgressListenerTests.kt index 0ab083e3ce..3b65a396e3 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/PBSProgressListenerTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/PBSProgressListenerTests.kt @@ -29,11 +29,11 @@ import io.realm.kotlin.mongodb.sync.ProgressMode import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.sync.SyncSession import io.realm.kotlin.mongodb.syncSession -import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.use +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.receiveOrFail import io.realm.kotlin.test.util.use @@ -70,7 +70,7 @@ class PBSProgressListenerTests { @BeforeTest fun setup() { RealmLog.setLevel(LogLevel.INFO) - app = TestApp(this::class.simpleName, appName = TEST_APP_PARTITION) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) partitionValue = org.mongodb.kbson.ObjectId().toString() } @@ -265,7 +265,7 @@ class PBSProgressListenerTests { fun completesOnClose() = runBlocking { val channel = TestChannel(capacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) - TestApp("completesOnClose", TEST_APP_PARTITION).use { app -> + TestApp("completesOnClose", DefaultPartitionBasedAppInitializer).use { app -> val user = app.createUserAndLogIn() val realm = Realm.open(createSyncConfig(user)) try { diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionExtensionsTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionExtensionsTests.kt index c254d30efd..6e032467b5 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionExtensionsTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionExtensionsTests.kt @@ -28,10 +28,10 @@ import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.sync.WaitForSync import io.realm.kotlin.mongodb.syncSession import io.realm.kotlin.query.RealmResults -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.use import kotlinx.coroutines.TimeoutCancellationException @@ -58,7 +58,7 @@ class SubscriptionExtensionsTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" val user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionSetTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionSetTests.kt index 993957978e..6c28da7467 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionSetTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionSetTests.kt @@ -24,12 +24,12 @@ import io.realm.kotlin.mongodb.subscriptions import io.realm.kotlin.mongodb.sync.Subscription import io.realm.kotlin.mongodb.sync.SubscriptionSetState import io.realm.kotlin.mongodb.sync.SyncConfiguration -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX -import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.waitForSynchronizationOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.use +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.use import kotlin.test.AfterTest @@ -56,7 +56,7 @@ class SubscriptionSetTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" val user = runBlocking { app.createUserAndLogIn(email, password) @@ -89,7 +89,7 @@ class SubscriptionSetTests { @Test fun subscriptions_failOnNonFlexibleSyncRealms() { - TestApp(this::class.simpleName, appName = TEST_APP_PARTITION).use { testApp -> + TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer).use { testApp -> val (email, password) = TestHelper.randomEmail() to "password1234" val user = runBlocking { testApp.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionTests.kt index ffe94723a1..a6c8680285 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SubscriptionTests.kt @@ -28,6 +28,7 @@ import io.realm.kotlin.mongodb.sync.asQuery import io.realm.kotlin.query.RealmQuery import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper.randomEmail import io.realm.kotlin.test.util.toRealmInstant import io.realm.kotlin.types.RealmInstant @@ -55,7 +56,7 @@ class SubscriptionTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer,) val (email, password) = randomEmail() to "password1234" val user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientResetIntegrationTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientResetIntegrationTests.kt index 3a1011c711..66a26acc6b 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientResetIntegrationTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientResetIntegrationTests.kt @@ -47,9 +47,11 @@ import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TEST_APP_PARTITION import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.createUserAndLogIn -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.addEmailProvider -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializeFlexibleSync -import io.realm.kotlin.test.mongodb.util.TestAppInitializer.initializePartitionSync +import io.realm.kotlin.test.mongodb.util.BaasApp +import io.realm.kotlin.test.mongodb.util.BaseAppInitializer +import io.realm.kotlin.test.mongodb.util.addEmailProvider +import io.realm.kotlin.test.mongodb.util.initializeFlexibleSync +import io.realm.kotlin.test.mongodb.util.initializePartitionSync import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.receiveOrFail @@ -118,16 +120,15 @@ class SyncClientResetIntegrationTests { RealmLog.add(ClientResetLoggerInspector(logChannel)) val app = TestApp( this::class.simpleName, - appName = appName, - initialSetup = { app, service -> + object : BaseAppInitializer(appName, { app: BaasApp -> addEmailProvider(app) when (syncMode) { SyncMode.PARTITION_BASED -> - initializePartitionSync(app, service, recoveryDisabled) + initializePartitionSync(app, recoveryDisabled) SyncMode.FLEXIBLE -> - initializeFlexibleSync(app, service, recoveryDisabled) + initializeFlexibleSync(app, recoveryDisabled) } - } + }) {}, ) try { val (email, password) = TestHelper.randomEmail() to "password1234" diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientTests.kt index 52fe439bea..dd8d461b38 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncClientTests.kt @@ -8,6 +8,7 @@ import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.use import kotlin.test.AfterTest @@ -28,7 +29,7 @@ class SyncClientTests { @BeforeTest fun setup() { - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncConfigTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncConfigTests.kt index 235dadff6b..5474ac22cb 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncConfigTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncConfigTests.kt @@ -48,6 +48,7 @@ import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.TestHelper.getRandomKey import io.realm.kotlin.test.util.TestHelper.randomEmail @@ -86,7 +87,7 @@ class SyncConfigTests { @BeforeTest fun setup() { partitionValue = TestHelper.randomPartitionValue() - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) } @AfterTest diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncSessionTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncSessionTests.kt index 5832f3b170..ec372c0bb3 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncSessionTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncSessionTests.kt @@ -36,6 +36,7 @@ import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.platform.PlatformUtils import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper @@ -78,7 +79,7 @@ class SyncSessionTests { @BeforeTest fun setup() { partitionValue = TestHelper.randomPartitionValue() - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt index c9393a25de..3796be8bd4 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt @@ -62,6 +62,8 @@ import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.common.utils.uploadAllLocalChangesOrFail import io.realm.kotlin.test.mongodb.createUserAndLogIn import io.realm.kotlin.test.mongodb.use +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.platform.PlatformUtils import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper @@ -121,7 +123,7 @@ class SyncedRealmTests { @BeforeTest fun setup() { partitionValue = TestHelper.randomPartitionValue() - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) val (email, password) = randomEmail() to "password1234" val user = runBlocking { @@ -922,7 +924,7 @@ class SyncedRealmTests { fun writeCopyTo_localToFlexibleSync_throws() = runBlocking { TestApp( this::class.simpleName, - appName = io.realm.kotlin.test.mongodb.TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.syncRootDirectory(PlatformUtils.createTempDir("flx-sync-")) } @@ -1001,7 +1003,7 @@ class SyncedRealmTests { fun writeCopyTo_flexibleSyncToLocal() = runBlocking { TestApp( "writeCopyTo_flexibleSyncToLocal", - appName = io.realm.kotlin.test.mongodb.TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.syncRootDirectory(PlatformUtils.createTempDir("flx-sync-")) } @@ -1124,7 +1126,7 @@ class SyncedRealmTests { fun writeCopyTo_flexibleSyncToFlexibleSync() = runBlocking { TestApp( "writeCopyTo_flexibleSyncToFlexibleSync", - appName = io.realm.kotlin.test.mongodb.TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.syncRootDirectory(PlatformUtils.createTempDir("flx-sync-")) } @@ -1227,7 +1229,7 @@ class SyncedRealmTests { fun accessSessionAfterRemoteChange() = runBlocking { TestApp( "accessSessionAfterRemoteChange", - appName = io.realm.kotlin.test.mongodb.TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.syncRootDirectory(PlatformUtils.createTempDir("flx-sync-")) } @@ -1418,7 +1420,7 @@ class SyncedRealmTests { fun createInitialRealmFx() = runBlocking { TestApp( "createInitialRealmFx", - appName = io.realm.kotlin.test.mongodb.TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.syncRootDirectory(PlatformUtils.createTempDir("flx-sync-")) } @@ -1473,7 +1475,7 @@ class SyncedRealmTests { @OptIn(ExperimentalKBsonSerializerApi::class) TestApp( "initialRealm_flexibleSync", - appName = io.realm.kotlin.test.mongodb.TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.syncRootDirectory(PlatformUtils.createTempDir("flx-sync-")) } diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserProfileTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserProfileTests.kt index 87e056b344..5c5593f9c6 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserProfileTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserProfileTests.kt @@ -27,6 +27,7 @@ import io.realm.kotlin.mongodb.ext.profileAsBsonDocument import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.SerializationException @@ -102,6 +103,7 @@ class UserProfileTests { fun setUp() { app = TestApp( this::class.simpleName, + DefaultPartitionBasedAppInitializer, networkTransport = object : NetworkTransport { override val authorizationHeaderName: String? get() = "" diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserTests.kt index e51b042d48..6efbbd81e0 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/UserTests.kt @@ -39,6 +39,7 @@ import io.realm.kotlin.test.mongodb.common.mongo.CustomDataType import io.realm.kotlin.test.mongodb.common.mongo.TEST_SERVICE_NAME import io.realm.kotlin.test.mongodb.common.mongo.customEjsonSerializer import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.TestHelper.randomEmail import kotlinx.serialization.SerialName @@ -71,7 +72,7 @@ class UserTests { @BeforeTest fun setUp() { - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) } @AfterTest diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt index 20195dd79d..1880242e0a 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt @@ -24,11 +24,8 @@ import io.realm.kotlin.internal.util.CoroutineDispatcherFactory import io.realm.kotlin.internal.util.use import io.realm.kotlin.mongodb.internal.KtorNetworkTransport import io.realm.kotlin.test.mongodb.TEST_SERVER_BASE_URL -import io.realm.kotlin.test.mongodb.syncServerAppName import io.realm.kotlin.test.mongodb.util.AppServicesClient -import io.realm.kotlin.test.mongodb.util.BaasApp -import io.realm.kotlin.test.mongodb.util.KtorTestAppInitializer.initialize -import io.realm.kotlin.test.mongodb.util.Service +import io.realm.kotlin.test.mongodb.util.KtorTestAppInitializer import io.realm.kotlin.test.mongodb.util.TEST_METHODS import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.receiveOrFail @@ -66,9 +63,7 @@ internal class KtorNetworkTransportTest { dispatcher = dispatcher ) appClient.run { - getOrCreateApp(syncServerAppName("ktor")) { app: BaasApp, service: Service -> - initialize(app, TEST_METHODS) - } + getOrCreateApp(KtorTestAppInitializer) } } diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoClientTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoClientTests.kt index d2399aaeb0..e27973998f 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoClientTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoClientTests.kt @@ -23,9 +23,9 @@ import io.realm.kotlin.mongodb.ext.collection import io.realm.kotlin.mongodb.ext.insertOne import io.realm.kotlin.mongodb.mongo.MongoClient import io.realm.kotlin.mongodb.mongo.realmSerializerModule -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import kotlinx.serialization.SerializationException import org.mongodb.kbson.ExperimentalKBsonSerializerApi import org.mongodb.kbson.serialization.EJson @@ -47,7 +47,7 @@ class MongoClientTests { fun setUp() { app = TestApp( this::class.simpleName, - appName = TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, ) val user = app.createUserAndLogin() client = user.mongoClient(TEST_SERVICE_NAME, eJson = EJson(serializersModule = realmSerializerModule(setOf(CollectionDataType::class)))) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoCollectionTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoCollectionTests.kt index d4c38b4969..91ef0aea63 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoCollectionTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoCollectionTests.kt @@ -48,12 +48,12 @@ import io.realm.kotlin.mongodb.mongo.realmSerializerModule import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.mongodb.syncSession import io.realm.kotlin.notifications.ResultsChange -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage import io.realm.kotlin.test.mongodb.common.utils.retry +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import io.realm.kotlin.test.util.receiveOrFail import io.realm.kotlin.test.util.use import io.realm.kotlin.types.BaseRealmObject @@ -158,7 +158,7 @@ sealed class MongoCollectionTests { open fun setUp() { app = TestApp( testId = this::class.simpleName, - appName = TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, builder = { it.httpLogObfuscator(null) } diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoDatabaseTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoDatabaseTests.kt index ed135800ed..fc99981af3 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoDatabaseTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/mongo/MongoDatabaseTests.kt @@ -21,9 +21,9 @@ import io.realm.kotlin.internal.platform.runBlocking import io.realm.kotlin.mongodb.ext.insertOne import io.realm.kotlin.mongodb.mongo.MongoClient import io.realm.kotlin.mongodb.mongo.MongoDatabase -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage +import io.realm.kotlin.test.mongodb.util.DefaultFlexibleSyncAppInitializer import kotlinx.serialization.SerializationException import org.mongodb.kbson.BsonDocument import org.mongodb.kbson.BsonInt32 @@ -48,7 +48,7 @@ class MongoDatabaseTests { fun setUp() { app = TestApp( this::class.simpleName, - appName = TEST_APP_FLEX, + DefaultFlexibleSyncAppInitializer, ) val user = app.createUserAndLogin() client = user.mongoClient(TEST_SERVICE_NAME) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/nonlatin/NonLatinTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/nonlatin/NonLatinTests.kt index fd880b43b9..93032998eb 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/nonlatin/NonLatinTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/nonlatin/NonLatinTests.kt @@ -10,6 +10,7 @@ import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.PARTITION_BASED_SCHEMA import io.realm.kotlin.test.mongodb.createUserAndLogIn +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.TestHelper import io.realm.kotlin.test.util.receiveOrFail @@ -37,7 +38,7 @@ class NonLatinTests { fun setup() { partitionValue = TestHelper.randomPartitionValue() @OptIn(ExperimentalKBsonSerializerApi::class) - app = TestApp(this::class.simpleName) + app = TestApp(this::class.simpleName, DefaultPartitionBasedAppInitializer) val (email, password) = TestHelper.randomEmail() to "password1234" user = runBlocking { app.createUserAndLogIn(email, password) diff --git a/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/RealmTests.kt b/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/RealmTests.kt index e63ed5fde9..3d0d9e5df5 100644 --- a/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/RealmTests.kt +++ b/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/RealmTests.kt @@ -22,6 +22,7 @@ import io.realm.kotlin.entities.sync.ParentPk import io.realm.kotlin.mongodb.Credentials import io.realm.kotlin.mongodb.sync.SyncConfiguration import io.realm.kotlin.test.mongodb.TestApp +import io.realm.kotlin.test.mongodb.util.DefaultPartitionBasedAppInitializer import io.realm.kotlin.test.platform.PlatformUtils import io.realm.kotlin.test.util.TestHelper import kotlinx.coroutines.runBlocking @@ -42,7 +43,7 @@ class RealmTests { @Ignore // See https://github.com/realm/realm-kotlin/issues/1627 fun cleanupAllRealmThreadsOnClose() = runBlocking { @OptIn(ExperimentalKBsonSerializerApi::class) - val app = TestApp("cleanupAllRealmThreadsOnClose") + val app = TestApp("cleanupAllRealmThreadsOnClose", DefaultPartitionBasedAppInitializer) val user = app.login(Credentials.anonymous()) val configuration = SyncConfiguration.create(user, TestHelper.randomPartitionValue(), setOf(ParentPk::class, ChildPk::class)) Realm.open(configuration).close() From 1187d4589cdad494ef33709723f0fef632d4bbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Mon, 24 Jun 2024 16:03:44 +0200 Subject: [PATCH 02/10] Fix email auth test app setup --- .../kotlin/test/mongodb/util/TestAppInitializer.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt index b017e0539f..512e07624d 100644 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/TestAppInitializer.kt @@ -108,17 +108,23 @@ open class BaseAppInitializer( block?.invoke(this, app) } app.setDevelopmentMode(true) - addEmailProvider(app) } } } } object DefaultPartitionBasedAppInitializer : - BaseAppInitializer(TEST_APP_PARTITION, { initializePartitionSync(it) }) + BaseAppInitializer(TEST_APP_PARTITION, {app -> + addEmailProvider(app) + initializePartitionSync(app) } + ) object DefaultFlexibleSyncAppInitializer : - BaseAppInitializer(TEST_APP_FLEX, { initializeFlexibleSync(it) }) + BaseAppInitializer(TEST_APP_FLEX, { app -> + addEmailProvider(app) + initializeFlexibleSync(app) } + ) + @Suppress("LongMethod") suspend fun AppServicesClient.initializeFlexibleSync( From 8194c985fa8ecb7a56beb71b0a46c8a72c8fb119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Mon, 24 Jun 2024 16:31:47 +0200 Subject: [PATCH 03/10] Add CHANGELOG entry --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8514c747d..3b68f8a560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,9 +25,10 @@ * Minimum R8: 8.0.34. ### Internal -- None. +- Reworked test app initializer framework. + -## 2.0.1 (YYYY-MM-DD) +## 2.0.1-SNAPSHOT (YYYY-MM-DD) ### Breaking changes * None. From 15637afe8d9f65796413a39f61649c4c117567e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Mon, 24 Jun 2024 17:13:34 +0200 Subject: [PATCH 04/10] Fix ktor test app setup --- .../mongodb/util/KtorTestAppInitializer.kt | 76 ------------------- .../internal/KtorNetworkTransportTest.kt | 62 ++++++++++++++- 2 files changed, 61 insertions(+), 77 deletions(-) delete mode 100644 packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt deleted file mode 100644 index 3511c6914d..0000000000 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/KtorTestAppInitializer.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2022 Realm Inc. - * - * 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 io.realm.kotlin.test.mongodb.util - -import io.ktor.http.HttpMethod - -object KtorTestAppInitializer : AppInitializer { - override suspend fun initialize(client: AppServicesClient, app: BaasApp) { - client.initialize(app, TEST_METHODS) - } - - // Setups the app with the functions and https endpoints required to run the KtorNetworkTransportTests - suspend fun AppServicesClient.initialize(app: BaasApp, methods: List) = - with(app) { - // We have to create a function per method because the request parameter does not - // has what method triggered it. - methods.forEach { httpMethod: HttpMethod -> - val method = httpMethod.value - val function = addFunction( - Function( - name = "test_network_transport_$method", - runAsSystem = true, - source = - """ - exports = async function (request, response) { - response.setHeader('Content-Type', 'text/plain'); - let isSuccess = request.query["success"] == "true"; - - if (isSuccess) { - response.setStatusCode(200); - response.setBody("$method-success"); - } else { - response.setStatusCode(500); - response.setBody("$method-failure"); - } - } - """.trimIndent() - ) - ) - - addEndpoint( - """ - { - "route": "/test_network_transport", - "function_name": "${function.name}", - "function_id": "${function._id}", - "http_method": "$method", - "validation_method": "NO_VALIDATION", - "secret_id": "", - "secret_name": "", - "create_user_on_auth": false, - "fetch_custom_user_data": false, - "respond_result": false, - "disabled": false, - "return_type": "JSON" - } - """.trimIndent() - ) - } - } - - override val name: String = "ktor-test-app" -} diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt index 7cb4aac59f..2acb753971 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/internal/KtorNetworkTransportTest.kt @@ -26,8 +26,10 @@ import io.realm.kotlin.internal.util.CoroutineDispatcherFactory import io.realm.kotlin.internal.util.use import io.realm.kotlin.mongodb.internal.KtorNetworkTransport import io.realm.kotlin.test.mongodb.TEST_SERVER_BASE_URL +import io.realm.kotlin.test.mongodb.util.AppInitializer import io.realm.kotlin.test.mongodb.util.AppServicesClient -import io.realm.kotlin.test.mongodb.util.KtorTestAppInitializer +import io.realm.kotlin.test.mongodb.util.BaasApp +import io.realm.kotlin.test.mongodb.util.Function import io.realm.kotlin.test.util.TestChannel import io.realm.kotlin.test.util.receiveOrFail import io.realm.kotlin.test.util.trySendOrFail @@ -47,6 +49,64 @@ val TEST_METHODS = listOf( HttpMethod.Delete, ) +object KtorTestAppInitializer : AppInitializer { + override suspend fun initialize(client: AppServicesClient, app: BaasApp) { + client.initialize(app, TEST_METHODS) + } + + // Setups the app with the functions and https endpoints required to run the KtorNetworkTransportTests + suspend fun AppServicesClient.initialize(app: BaasApp, methods: List) = + with(app) { + // We have to create a function per method because the request parameter does not + // has what method triggered it. + methods.forEach { httpMethod: HttpMethod -> + val method = httpMethod.value + val function = addFunction( + Function( + name = "test_network_transport_$method", + runAsSystem = true, + source = + """ + exports = async function (request, response) { + response.setHeader('Content-Type', 'text/plain'); + let isSuccess = request.query["success"] == "true"; + + if (isSuccess) { + response.setStatusCode(200); + response.setBody("$method-success"); + } else { + response.setStatusCode(500); + response.setBody("$method-failure"); + } + } + """.trimIndent() + ) + ) + + addEndpoint( + """ + { + "route": "/test_network_transport", + "function_name": "${function.name}", + "function_id": "${function._id}", + "http_method": "$method", + "validation_method": "NO_VALIDATION", + "secret_id": "", + "secret_name": "", + "create_user_on_auth": false, + "fetch_custom_user_data": false, + "respond_result": false, + "disabled": false, + "return_type": "JSON" + } + """.trimIndent() + ) + } + } + + override val name: String = "ktor-test-app" +} + internal class KtorNetworkTransportTest { private lateinit var transport: KtorNetworkTransport private lateinit var endpoint: String From 64127839564c92689ee8078ae8bbf1242345b6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Wed, 26 Jun 2024 09:08:01 +0200 Subject: [PATCH 05/10] Fix app initializer for collection in mixed round trip tests --- .../io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt index cc3a39d559..47b248ce12 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt @@ -61,7 +61,6 @@ import io.realm.kotlin.query.RealmResults import io.realm.kotlin.schema.RealmClass import io.realm.kotlin.schema.RealmSchema import io.realm.kotlin.schema.ValuePropertyType -import io.realm.kotlin.test.mongodb.TEST_APP_FLEX import io.realm.kotlin.test.mongodb.TestApp import io.realm.kotlin.test.mongodb.asTestApp import io.realm.kotlin.test.mongodb.common.utils.assertFailsWithMessage @@ -722,7 +721,7 @@ class SyncedRealmTests { fun roundtripCollectionsInMixed() = runBlocking { val (email1, password1) = randomEmail() to "password1234" val (email2, password2) = randomEmail() to "password1234" - val app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + val app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val user1 = app.createUserAndLogIn(email1, password1) val user2 = app.createUserAndLogIn(email2, password2) @@ -805,7 +804,7 @@ class SyncedRealmTests { fun collectionsInMixed_asFlow() = runBlocking { val (email1, password1) = randomEmail() to "password1234" val (email2, password2) = randomEmail() to "password1234" - val app = TestApp(this::class.simpleName, appName = TEST_APP_FLEX) + val app = TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer) val user1 = app.createUserAndLogIn(email1, password1) val user2 = app.createUserAndLogIn(email2, password2) From fda7ba30042dc9352089c6be006e4c8692e92305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Wed, 26 Jun 2024 11:24:34 +0200 Subject: [PATCH 06/10] Fix test app initializers for function and http obfuscator tests --- .../kotlin/test/mongodb/common/FunctionsTests.kt | 16 +++++++++------- .../mongodb/common/HttpLogObfuscatorTests.kt | 10 ++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt index 70bfdc3ed6..20646dd322 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/FunctionsTests.kt @@ -47,6 +47,7 @@ import io.realm.kotlin.test.mongodb.util.FIRST_ARG_FUNCTION import io.realm.kotlin.test.mongodb.util.NULL_FUNCTION import io.realm.kotlin.test.mongodb.util.SUM_FUNCTION import io.realm.kotlin.test.mongodb.util.VOID_FUNCTION +import io.realm.kotlin.test.mongodb.util.addEmailProvider import io.realm.kotlin.test.util.TypeDescriptor import io.realm.kotlin.types.MutableRealmInt import io.realm.kotlin.types.RealmAny @@ -201,13 +202,14 @@ class FunctionsTests { FunctionsTests::class.simpleName, object : BaseAppInitializer( syncServerAppName("funcs"), - { - it.addFunction(FIRST_ARG_FUNCTION) - it.addFunction(NULL_FUNCTION) - it.addFunction(SUM_FUNCTION) - it.addFunction(ERROR_FUNCTION) - it.addFunction(VOID_FUNCTION) - it.addFunction(AUTHORIZED_ONLY_FUNCTION) + { app -> + addEmailProvider(app) + app.addFunction(FIRST_ARG_FUNCTION) + app.addFunction(NULL_FUNCTION) + app.addFunction(SUM_FUNCTION) + app.addFunction(ERROR_FUNCTION) + app.addFunction(VOID_FUNCTION) + app.addFunction(AUTHORIZED_ONLY_FUNCTION) } ) {}, ejson = EJson( diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt index 4f9558acc5..2915481b4c 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt @@ -33,6 +33,7 @@ import io.realm.kotlin.test.mongodb.util.BaseAppInitializer import io.realm.kotlin.test.mongodb.util.FIRST_ARG_FUNCTION import io.realm.kotlin.test.mongodb.util.NULL_FUNCTION import io.realm.kotlin.test.mongodb.util.SUM_FUNCTION +import io.realm.kotlin.test.mongodb.util.addEmailProvider import io.realm.kotlin.test.util.receiveOrFail import kotlinx.coroutines.CancellationException import kotlinx.coroutines.async @@ -124,10 +125,11 @@ class HttpLogObfuscatorTests { private fun initApp(): TestApp { return TestApp( this::class.simpleName, - object : BaseAppInitializer(syncServerAppName("obfsctr"), { - it.addFunction(FIRST_ARG_FUNCTION) - it.addFunction(SUM_FUNCTION) - it.addFunction(NULL_FUNCTION) + object : BaseAppInitializer(syncServerAppName("obfsctr"), { app -> + addEmailProvider(app) + app.addFunction(FIRST_ARG_FUNCTION) + app.addFunction(SUM_FUNCTION) + app.addFunction(NULL_FUNCTION) }) {} ) } From 11b38162c40ad379f6dc88675312fd9d3a1dd254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Wed, 26 Jun 2024 12:46:18 +0200 Subject: [PATCH 07/10] More test app initializer adjustments --- .../kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt index 2915481b4c..bb8cffc67d 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/HttpLogObfuscatorTests.kt @@ -152,10 +152,11 @@ class HttpLogObfuscatorTests { "nullObfuscator", object : BaseAppInitializer( syncServerAppName("null-obf"), - { - it.addFunction(FIRST_ARG_FUNCTION) - it.addFunction(SUM_FUNCTION) - it.addFunction(NULL_FUNCTION) + { app -> + addEmailProvider(app) + app.addFunction(FIRST_ARG_FUNCTION) + app.addFunction(SUM_FUNCTION) + app.addFunction(NULL_FUNCTION) } ) {}, builder = { it.httpLogObfuscator(null) }, From 30dcad65b7cb468d3fe6716822fd734fa2046f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Thu, 27 Jun 2024 13:19:02 +0200 Subject: [PATCH 08/10] Make collection in mixed round trip tests repeatable --- .../kotlin/entities/JsonStyleRealmObject.kt | 5 ++- .../common/RealmAnyNestedCollectionTests.kt | 43 ++++++++++--------- ...ealmAnyNestedCollectionNotificationTest.kt | 1 - ...ealmAnyNestedDictionaryNotificationTest.kt | 1 - .../RealmAnyNestedListNotificationTest.kt | 3 +- .../test/mongodb/common/SyncedRealmTests.kt | 27 +++++++----- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/packages/test-base/src/commonMain/kotlin/io/realm/kotlin/entities/JsonStyleRealmObject.kt b/packages/test-base/src/commonMain/kotlin/io/realm/kotlin/entities/JsonStyleRealmObject.kt index 41f1afce62..bb8eb8a34a 100644 --- a/packages/test-base/src/commonMain/kotlin/io/realm/kotlin/entities/JsonStyleRealmObject.kt +++ b/packages/test-base/src/commonMain/kotlin/io/realm/kotlin/entities/JsonStyleRealmObject.kt @@ -23,9 +23,10 @@ import io.realm.kotlin.types.annotations.PrimaryKey import org.mongodb.kbson.ObjectId class JsonStyleRealmObject : RealmObject { + // Act as partition key to separate individual test runs + var selector: String = "DEFAULT" @PrimaryKey @PersistedName("_id") - var id: String = ObjectId().toHexString() - var selector: String = "DEFAULT" + var id: ObjectId = ObjectId() var value: RealmAny? = null } diff --git a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt index e13edb5c8f..f3a6fb0f7a 100644 --- a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt +++ b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/RealmAnyNestedCollectionTests.kt @@ -30,6 +30,7 @@ import io.realm.kotlin.internal.platform.runBlocking import io.realm.kotlin.test.common.utils.assertFailsWithMessage import io.realm.kotlin.test.platform.PlatformUtils import io.realm.kotlin.types.RealmAny +import org.mongodb.kbson.ObjectId import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test @@ -527,26 +528,26 @@ class RealmAnyNestedCollectionTests { @Test fun query() = runBlocking { + var listId: ObjectId? = null + var dictId: ObjectId? = null + var embeddedId: ObjectId? = null realm.write { - copyToRealm( + listId = copyToRealm( JsonStyleRealmObject().apply { - id = "LIST" value = realmAnyListOf(4, 5, 6) } - ) - copyToRealm( + ).id + dictId = copyToRealm( JsonStyleRealmObject().apply { - id = "DICT" value = realmAnyDictionaryOf( "key1" to 7, "key2" to 8, "key3" to 9, ) } - ) - copyToRealm( + ).id + embeddedId = copyToRealm( JsonStyleRealmObject().apply { - id = "EMBEDDED" value = realmAnyListOf( listOf(4, 5, 6), mapOf( @@ -556,35 +557,35 @@ class RealmAnyNestedCollectionTests { ) ) } - ) + ).id } assertEquals(3, realm.query().find().size) // Matching lists realm.query("value[0] == 4").find().single().run { - assertEquals("LIST", id) + assertEquals(listId, id) } realm.query("value[*] == 4").find().single().run { - assertEquals("LIST", id) + assertEquals(listId, id) } realm.query("value[*] == {4, 5, 6}").find().single().run { - assertEquals("LIST", id) + assertEquals(listId, id) } // Matching dictionaries realm.query("value.key1 == 7").find().single().run { - assertEquals("DICT", id) + assertEquals(dictId, id) } realm.query("value['key1'] == 7").find().single().run { - assertEquals("DICT", id) + assertEquals(dictId, id) } realm.query("value[*] == 7").find().single().run { - assertEquals("DICT", id) + assertEquals(dictId, id) } assertEquals(0, realm.query("value.unknown == 3").find().size) realm.query("value.@keys == 'key1'").find().single().run { - assertEquals("DICT", id) + assertEquals(dictId, id) } assertEquals(0, realm.query("value.@keys == 'unknown'").find().size) @@ -593,19 +594,19 @@ class RealmAnyNestedCollectionTests { // Matching across all elements and in nested structures realm.query("value[*][*] == 4").find().single().run { - assertEquals("EMBEDDED", id) + assertEquals(embeddedId, id) } realm.query("value[*][*] == 7").find().single().run { - assertEquals("EMBEDDED", id) + assertEquals(embeddedId, id) } realm.query("value[*].@keys == 'key1'").find().single().run { - assertEquals("EMBEDDED", id) + assertEquals(embeddedId, id) } realm.query("value[*].key3[0] == 9").find().single().run { - assertEquals("EMBEDDED", id) + assertEquals(embeddedId, id) } realm.query("value[0][*] == {4, 5, 6}").find().single().run { - assertEquals("EMBEDDED", id) + assertEquals(embeddedId, id) } // FIXME Core issue https://github.com/realm/realm-core/issues/7393 // realm.query("value[*][*] == {4, 5, 6}").find().single().run { diff --git a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedCollectionNotificationTest.kt b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedCollectionNotificationTest.kt index 9d1c69dc25..bc7e30da2d 100644 --- a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedCollectionNotificationTest.kt +++ b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedCollectionNotificationTest.kt @@ -71,7 +71,6 @@ class RealmAnyNestedCollectionNotificationTest { val o: JsonStyleRealmObject = realm.write { copyToRealm( JsonStyleRealmObject().apply { - id = "SET" value = realmAnyListOf(realmAnyListOf(1, 2, 3)) } ) diff --git a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedDictionaryNotificationTest.kt b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedDictionaryNotificationTest.kt index 0b25592dd4..baf7aee88a 100644 --- a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedDictionaryNotificationTest.kt +++ b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedDictionaryNotificationTest.kt @@ -84,7 +84,6 @@ class RealmAnyNestedDictionaryNotificationTest : FlowableTests, DeletableEntityN val o: JsonStyleRealmObject = realm.write { copyToRealm( JsonStyleRealmObject().apply { - id = "DICTIONARY" value = realmAnyDictionaryOf( "root" to realmAnyDictionaryOf( "key1" to 1, diff --git a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedListNotificationTest.kt b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedListNotificationTest.kt index fab126948e..e3a263419e 100644 --- a/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedListNotificationTest.kt +++ b/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/notifications/RealmAnyNestedListNotificationTest.kt @@ -84,7 +84,6 @@ class RealmAnyNestedListNotificationTest : FlowableTests, DeletableEntityNotific val o: JsonStyleRealmObject = realm.write { copyToRealm( JsonStyleRealmObject().apply { - id = "LIST" value = realmAnyListOf(realmAnyListOf(1, 2, 3)) } ) @@ -281,7 +280,7 @@ class RealmAnyNestedListNotificationTest : FlowableTests, DeletableEntityNotific val asList = findLatest(parent)!!.value!!.asList() println(asList.size) asList.add( - RealmAny.create(JsonStyleRealmObject().apply { id = "CHILD" }) + RealmAny.create(JsonStyleRealmObject()) ) } channel.receiveOrFail(message = "List add").let { diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt index 47b248ce12..239d1254b5 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt @@ -727,6 +727,8 @@ class SyncedRealmTests { // Create object with all types val selector = ObjectId().toString() + var parentId: ObjectId? = null + var childId: ObjectId? = null createFlexibleSyncConfig( user = user1, @@ -738,14 +740,13 @@ class SyncedRealmTests { realm.write { val child = ( JsonStyleRealmObject().apply { - this.id = "CHILD" this.selector = selector } ) + childId = child.id - copyToRealm( + parentId = copyToRealm( JsonStyleRealmObject().apply { - this.id = "PARENT" this.selector = selector value = realmAnyDictionaryOf( "primitive" to 1, @@ -754,7 +755,7 @@ class SyncedRealmTests { "dictionary" to realmAnyDictionaryOf("dictkey1" to 1, "dictkey2" to "Realm", "dictkey3" to child, "dictkey4" to realmAnyListOf(1, 2, 3)) ) } - ) + ).id } realm.syncSession.uploadAllLocalChangesOrFail() } @@ -766,31 +767,37 @@ class SyncedRealmTests { } ).let { config -> Realm.open(config).use { realm -> + println("download changes") realm.syncSession.downloadAllServerChanges(10.seconds) - val flow = realm.query("_id = $0", "PARENT").asFlow() + println("downloaded changes") + val flow = realm.query("_id = $0", parentId).asFlow() val parent = withTimeout(10.seconds) { - flow.first { + println("get object") + val x = flow.first { it.list.size >= 1 }.list[0] + println("x") + x } + println("get parent") parent.let { val value = it.value!!.asDictionary() assertEquals(RealmAny.Companion.create(1), value["primitive"]) value["list"]!!.asList().let { assertEquals(1, it[0]!!.asInt()) assertEquals("Realm", it[1]!!.asString()) - assertEquals("CHILD", it[2]!!.asRealmObject().id) + assertEquals(childId, it[2]!!.asRealmObject().id) it[3]!!.asDictionary().let { dict -> assertEquals(1, dict["listkey1"]!!.asInt()) assertEquals("Realm", dict["listkey2"]!!.asString()) - assertEquals("CHILD", dict["listkey3"]!!.asRealmObject().id) + assertEquals(childId, dict["listkey3"]!!.asRealmObject().id) } - assertEquals("CHILD", it[2]!!.asRealmObject().id) + assertEquals(childId, it[2]!!.asRealmObject().id) } value["dictionary"]!!.asDictionary().let { assertEquals(1, it["dictkey1"]!!.asInt()) assertEquals("Realm", it["dictkey2"]!!.asString()) - assertEquals("CHILD", it["dictkey3"]!!.asRealmObject().id) + assertEquals(childId, it["dictkey3"]!!.asRealmObject().id) it["dictkey4"]!!.asList().let { assertEquals(realmAnyListOf(1, 2, 3).asList(), it) } From 514990f4eec08aba177694cef2205170d399fca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Fri, 5 Jul 2024 13:58:19 +0200 Subject: [PATCH 09/10] Removed debug output --- .../io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt index 239d1254b5..8523543cdf 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt @@ -767,9 +767,7 @@ class SyncedRealmTests { } ).let { config -> Realm.open(config).use { realm -> - println("download changes") realm.syncSession.downloadAllServerChanges(10.seconds) - println("downloaded changes") val flow = realm.query("_id = $0", parentId).asFlow() val parent = withTimeout(10.seconds) { println("get object") From 965644be2999b6b1ed12aaef9a834f96ca6c599c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Fri, 5 Jul 2024 14:15:58 +0200 Subject: [PATCH 10/10] More debug clean up --- .../io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt index 8523543cdf..6755835db8 100644 --- a/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt +++ b/packages/test-sync/src/commonTest/kotlin/io/realm/kotlin/test/mongodb/common/SyncedRealmTests.kt @@ -770,14 +770,10 @@ class SyncedRealmTests { realm.syncSession.downloadAllServerChanges(10.seconds) val flow = realm.query("_id = $0", parentId).asFlow() val parent = withTimeout(10.seconds) { - println("get object") - val x = flow.first { + flow.first { it.list.size >= 1 }.list[0] - println("x") - x } - println("get parent") parent.let { val value = it.value!!.asDictionary() assertEquals(RealmAny.Companion.create(1), value["primitive"])