diff --git a/packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt b/packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt index ce9e60d32c..2d5974fa12 100644 --- a/packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt +++ b/packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt @@ -649,6 +649,8 @@ expect object RealmInterop { user: RealmUserPointer, partition: String ): RealmSyncConfigurationPointer + // Flexible Sync + fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer fun realm_sync_config_set_error_handler( syncConfig: RealmSyncConfigurationPointer, errorHandler: SyncErrorCallback @@ -786,9 +788,6 @@ expect object RealmInterop { syncConfiguration: RealmSyncConfigurationPointer ) - // Flexible Sync - fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer - // Flexible Sync Subscription fun realm_sync_subscription_id(subscription: RealmSubscriptionPointer): ObjectId fun realm_sync_subscription_name(subscription: RealmSubscriptionPointer): String? 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 33f29cf9e5..6247ab2409 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 @@ -1981,7 +1981,11 @@ actual object RealmInterop { } actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer { - return LongPointerWrapper(realmc.realm_flx_sync_config_new(user.cptr())) + return LongPointerWrapper(realmc.realm_flx_sync_config_new(user.cptr())).also { ptr -> + // Stop the session immediately when the Realm is closed, so the lifecycle of the + // Sync Client thread is manageable. + realmc.realm_sync_config_set_session_stop_policy(ptr.cptr(), realm_sync_session_stop_policy_e.RLM_SYNC_SESSION_STOP_POLICY_IMMEDIATELY) + } } actual fun realm_sync_subscription_id(subscription: RealmSubscriptionPointer): ObjectId { 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 54fc9f530e..9c7f35a029 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 @@ -3317,6 +3317,14 @@ actual object RealmInterop { } } + actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer { + return CPointerWrapper(realm_wrapper.realm_flx_sync_config_new((user.cptr()))).also { ptr -> + // Stop the session immediately when the Realm is closed, so the lifecycle of the + // Sync Client thread is manageable. + realm_wrapper.realm_sync_config_set_session_stop_policy(ptr.cptr(), realm_sync_session_stop_policy_e.RLM_SYNC_SESSION_STOP_POLICY_IMMEDIATELY) + } + } + actual fun realm_app_sync_client_reconnect(app: RealmAppPointer) { realm_wrapper.realm_app_sync_client_reconnect(app.cptr()) } @@ -3332,10 +3340,6 @@ actual object RealmInterop { realm_wrapper.realm_config_set_sync_config(realmConfiguration.cptr(), syncConfiguration.cptr()) } - actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer { - return CPointerWrapper(realm_wrapper.realm_flx_sync_config_new((user.cptr()))) - } - actual fun realm_sync_subscription_id(subscription: RealmSubscriptionPointer): ObjectId { return ObjectId(realm_wrapper.realm_sync_subscription_id(subscription.cptr()).getBytes()) } 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 6a69c6513e..079ab3b377 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 @@ -122,9 +122,7 @@ open class TestApp private constructor( return } - println("TERMINATING SESSION") app.sync.waitForSessionsToTerminate() - println("SESSIONS TERMINATED: ${app.sync.hasSyncSessions}") // This is needed to "properly reset" all sessions across tests since deleting users // directly using the REST API doesn't do the trick 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 e80239fd7b..53728762cf 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 @@ -147,7 +147,6 @@ class FLXProgressListenerTests { @Test fun uploadProgressListener_changesOnly() = runBlocking { Realm.open(createSyncConfig(app.createUserAndLogin())).use { realm -> - realm.syncSession.downloadAllServerChanges(TIMEOUT) for (i in 0..3) { realm.writeSampleData(TEST_SIZE, timeout = TIMEOUT) realm.syncSession.progressAsFlow(Direction.UPLOAD, ProgressMode.CURRENT_CHANGES)