Skip to content

Commit

Permalink
Immediately terminating sync session
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Jul 19, 2024
1 parent e2723ee commit ead1fde
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RealmSyncConfigT>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,14 @@ actual object RealmInterop {
}
}

actual fun realm_flx_sync_config_new(user: RealmUserPointer): RealmSyncConfigurationPointer {
return CPointerWrapper<RealmSyncConfigT>(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())
}
Expand All @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ead1fde

Please sign in to comment.