diff --git a/CHANGELOG.md b/CHANGELOG.md index e8175512ba..241bf0af44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * None ### Fixed +* The `onBefore`, `onAfter`, and `onFallback` client reset callbacks were not called. ([#6201](https://github.com/realm/realm-js/issues/6201), since v12.0.0) * `Symbol.unscopables` has been implemented on the base class of `Realm.Results`, `Realm.List`, and `Realm.Set`. ([#6215](https://github.com/realm/realm-js/pull/6215)) ### Compatibility @@ -15,9 +16,7 @@ * File format: generates Realms with format v23 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms). ### Internal - - - +* Some disabled tests for client reset (partition based sync) have been enabled. ([#6201](https://github.com/realm/realm-js/issues/6201) ## 12.2.1 (2023-10-05) diff --git a/integration-tests/tests/src/tests/sync/client-reset.ts b/integration-tests/tests/src/tests/sync/client-reset.ts index b8f5c8b09c..ed191858e7 100644 --- a/integration-tests/tests/src/tests/sync/client-reset.ts +++ b/integration-tests/tests/src/tests/sync/client-reset.ts @@ -54,7 +54,17 @@ function getPartitionValue() { } async function triggerClientReset(app: App, user: User): Promise { - await user.functions.triggerClientReset(app.id, user.id); + const maxAttempts = 5; + let deleted = false; + let count = maxAttempts; + while (count > 0) { + deleted = (await user.functions.triggerClientReset(app.id, user.id)) as boolean; + if (deleted) { + return; + } + count--; + } + throw new Error(`Cannot trigger client reset in ${maxAttempts} attempts`); } async function waitServerSideClientResetDiscardUnsyncedChangesCallbacks( @@ -194,8 +204,8 @@ async function waitSimulatedClientResetDiscardUnsyncedChangesCallbacks( if (useFlexibleSync) { addSubscriptions(realm); } - await realm.syncSession?.uploadAllLocalChanges(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore calling undocumented method _simulateError realm.syncSession?._simulateError(211, "Simulate Client Reset", "realm::sync::ProtocolError", false); // 211 -> diverging histories @@ -283,7 +293,9 @@ function getSchema(useFlexibleSync: boolean) { } // FIXME: testing flexible sync is currently disabled as it is timing out -[false /*, true*/].forEach((useFlexibleSync) => { +// FIXME: ngrok reports "Syntax Error" when tiggerClientResetFunction() is used. +// Once ngrok behaves nicely, the skipped tests can be enabled. +[false /*, true*/].forEach((useFlexibleSync) => { describe.skipIf( environment.missingServer, `client reset handling (${getPartialTestTitle(useFlexibleSync)} sync)`, @@ -291,8 +303,8 @@ function getSchema(useFlexibleSync: boolean) { this.longTimeout(); // client reset with flexible sync can take quite some time importAppBefore( useFlexibleSync - ? buildAppConfig("with-flx").anonAuth().flexibleSync() - : buildAppConfig("with-pbs").anonAuth().partitionBasedSync(), + ? buildAppConfig("with-flx").anonAuth().flexibleSync() /* .triggerClientResetFunction() */ + : buildAppConfig("with-pbs").anonAuth().partitionBasedSync() /* .triggerClientResetFunction() */, ); authenticateUserBefore(); @@ -417,7 +429,7 @@ function getSchema(useFlexibleSync: boolean) { }); }); - it.skip(`client reset fails, the error handler is called (${getPartialTestTitle( + it(`client reset fails, the error handler is called (${getPartialTestTitle( useFlexibleSync, )})`, async function (this: RealmContext) { // if client reset fails, the error handler is called @@ -456,7 +468,7 @@ function getSchema(useFlexibleSync: boolean) { }); }); - it.skip(`handles discard local simulated client reset with ${getPartialTestTitle( + it(`handles discard local simulated client reset with ${getPartialTestTitle( useFlexibleSync, )} sync enabled`, async function (this: RealmContext) { // (i) using a client reset in "DiscardUnsyncedChanges" mode, a fresh copy @@ -481,7 +493,7 @@ function getSchema(useFlexibleSync: boolean) { ); }); - it.skip(`handles simulated client reset with recovery with ${getPartialTestTitle( + it(`handles simulated client reset with recovery with ${getPartialTestTitle( useFlexibleSync, )} sync enabled`, async function (this: RealmContext) { const clientResetBefore = (realm: Realm): void => { @@ -534,7 +546,8 @@ function getSchema(useFlexibleSync: boolean) { // of the Realm will be downloaded (resync) // (ii) two callback will be called, while the sync error handler is not // (iii) after the reset, the Realm can be used as before - this.longTimeout(); + this.timeout(5 * 60 * 1000); + this.retries(3); const clientResetBefore = (realm: Realm) => { expect(realm.schema.length).to.equal(2); }; diff --git a/integration-tests/tests/src/utils/ExtendedAppConfigBuilder.ts b/integration-tests/tests/src/utils/ExtendedAppConfigBuilder.ts index bfa9b28ca5..8fd3c8d84f 100644 --- a/integration-tests/tests/src/utils/ExtendedAppConfigBuilder.ts +++ b/integration-tests/tests/src/utils/ExtendedAppConfigBuilder.ts @@ -178,7 +178,7 @@ export class ExtendedAppConfigBuilder extends AppConfigBuilder { } triggerClientResetFunction() { - this.function({ + return this.function({ name: "triggerClientReset", private: false, run_as_system: true, diff --git a/packages/realm-app-importer/src/AdminApiClient.ts b/packages/realm-app-importer/src/AdminApiClient.ts index cebf3f23dc..fb67e1a5e1 100644 --- a/packages/realm-app-importer/src/AdminApiClient.ts +++ b/packages/realm-app-importer/src/AdminApiClient.ts @@ -379,6 +379,7 @@ export class AdminApiClient { if (typeof body === "object") { headers["content-type"] = "application/json"; } + console.log("FISK 111", { ...rest, body: JSON.stringify(body), headers, reactNative: { textStreaming: true } }); const response = await DefaultNetworkTransport.fetch(url, { ...rest, body: JSON.stringify(body), diff --git a/packages/realm/bindgen/js_opt_in_spec.yml b/packages/realm/bindgen/js_opt_in_spec.yml index 57e15cdfee..c394069606 100644 --- a/packages/realm/bindgen/js_opt_in_spec.yml +++ b/packages/realm/bindgen/js_opt_in_spec.yml @@ -77,6 +77,9 @@ records: - ssl_verify_callback - cancel_waits_on_nonfatal_error - proxy_config + - client_resync_mode + - notify_before_client_reset + - notify_after_client_reset SyncProxyConfig: fields: