diff --git a/packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt b/packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt index 0bcf8c3cd4..33f29cf9e5 100644 --- a/packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt +++ b/packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt @@ -1310,7 +1310,8 @@ actual object RealmInterop { } actual fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer { - return LongPointerWrapper(realmc.realm_app_config_get_sync_client_config(configPointer.cptr())) + // The configuration is owned by Core so don't track and release it through garbage collection of the NativePointer + return LongPointerWrapper(realmc.realm_app_config_get_sync_client_config(configPointer.cptr()), false) } actual fun realm_sync_client_config_set_default_binding_thread_observer(syncClientConfig: RealmSyncClientConfigurationPointer, appId: String) { diff --git a/packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt b/packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt index f7179fd4a2..54fc9f530e 100644 --- a/packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt +++ b/packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt @@ -2465,7 +2465,8 @@ actual object RealmInterop { } actual fun realm_app_config_get_sync_client_config(configPointer: RealmAppConfigurationPointer): RealmSyncClientConfigurationPointer { - return CPointerWrapper(realm_wrapper.realm_app_config_get_sync_client_config(configPointer.cptr())) + // The configuration is owned by Core so don't track and release it through garbage collection of the NativePointer + return CPointerWrapper(realm_wrapper.realm_app_config_get_sync_client_config(configPointer.cptr()), false) } actual fun realm_sync_client_config_set_default_binding_thread_observer( diff --git a/packages/external/core b/packages/external/core index c280bdb175..bc7ff1b0ba 160000 --- a/packages/external/core +++ b/packages/external/core @@ -1 +1 @@ -Subproject commit c280bdb17522323d5c30dc32a2b9efc9dc80ca3b +Subproject commit bc7ff1b0ba48b187757fdfa26bec65bcb6753b98 diff --git a/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt b/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt new file mode 100644 index 0000000000..635e4ee501 --- /dev/null +++ b/packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt @@ -0,0 +1,76 @@ +package io.realm.kotlin.test.mongodb.jvm + +import io.realm.kotlin.Realm +import io.realm.kotlin.entities.sync.SyncObjectWithAllTypes +import io.realm.kotlin.ext.query +import io.realm.kotlin.internal.platform.runBlocking +import io.realm.kotlin.log.LogCategory +import io.realm.kotlin.log.LogLevel +import io.realm.kotlin.log.RealmLog +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.TestApp +import io.realm.kotlin.test.mongodb.common.FLEXIBLE_SYNC_SCHEMA +import io.realm.kotlin.test.mongodb.common.utils.CustomLogCollector +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.use +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue +import kotlin.time.Duration.Companion.seconds + +class PlatformNetworkingTests { + + private val TIMEOUT = 10.seconds + + @Test + fun syncRoundTrip() = runBlocking { + setOf(true, false).forEach { platformNetworking -> + TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer, builder = { + it.usePlatformNetworking(platformNetworking) + }).use { app -> + val selector = org.mongodb.kbson.ObjectId().toString() + + // Setup logger to capture WebSocketClient log messages + val logger = CustomLogCollector() + RealmLog.add(logger) + RealmLog.setLevel(LogLevel.DEBUG, LogCategory.Realm.Sdk) + + Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)).use { uploadRealm -> + Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)).use { realm -> + uploadRealm.write { + copyToRealm( + SyncObjectWithAllTypes().apply { + stringField = selector + } + ) + } + uploadRealm.syncSession.uploadAllLocalChanges(TIMEOUT) + realm.syncSession.downloadAllServerChanges(TIMEOUT) + assertEquals(1, realm.query().find().size) + } + } + assertTrue( + if (platformNetworking) { + logger.logs.any { it.contains("\\[Websocket.*\\] onOpen".toRegex()) } + } else { + logger.logs.none { it.contains("\\[Websocket.*\\] onOpen".toRegex()) } + }, + "Failed to verify log statements for : platformNetworking=$platformNetworking" + ) + } + } + } + + private fun createSyncConfig( + user: User, + selector: String + ): SyncConfiguration { + return SyncConfiguration.Builder(user, FLEXIBLE_SYNC_SCHEMA).initialSubscriptions { + add(it.query("stringField = $0", selector)) + }.build() + } +}