From db15e30d9a68ff286c736e2711fae130d4875cad Mon Sep 17 00:00:00 2001 From: Tom Duncalf Date: Wed, 1 Jun 2022 17:39:57 +0100 Subject: [PATCH 1/5] Fix for updated flexible sync error message --- .../tests/src/tests/sync/flexible.ts | 18 +++++----- .../tests/src/utils/expect-sync-error.ts | 34 +++++++++++++++++-- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/integration-tests/tests/src/tests/sync/flexible.ts b/integration-tests/tests/src/tests/sync/flexible.ts index 4f2aedb2d3..332cf1c607 100644 --- a/integration-tests/tests/src/tests/sync/flexible.ts +++ b/integration-tests/tests/src/tests/sync/flexible.ts @@ -33,8 +33,8 @@ import Realm, { BSON, ClientResetMode, FlexibleSyncConfiguration, SessionStopPol import { authenticateUserBefore, importAppBefore, openRealmBeforeEach } from "../../hooks"; import { DogSchema, IPerson, PersonSchema } from "../../schemas/person-and-dog-with-object-ids"; -import { expectClientResetError } from "../../utils/expect-sync-error"; -import { closeAndReopenRealm, closeRealm, closeThisRealm } from "../../utils/close-realm"; +import { expectInvalidWriteSyncError } from "../../utils/expect-sync-error"; +import { closeAndReopenRealm, closeRealm } from "../../utils/close-realm"; const FlexiblePersonSchema = { ...PersonSchema, properties: { ...PersonSchema.properties, nonQueryable: "string?" } }; @@ -1568,9 +1568,9 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () { // TODO test more complex integration scenarios, e.g. links, embedded objects, collections, complex queries - describe("client reset scenarios", function () { - it("triggers a client reset if items are added without a subscription", async function (this: RealmContext) { - await expectClientResetError(this.config, this.user, (realm) => { + describe("error scenarios", function () { + it("triggers an error if items are added without a subscription", async function (this: RealmContext) { + await expectInvalidWriteSyncError(this.config, this.user, (realm) => { realm.write(() => { return realm.create(FlexiblePersonSchema.name, { _id: new BSON.ObjectId(), @@ -1581,10 +1581,10 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () { }); }); - it("triggers a client reset and deletes the item if an item not matching the filter is created", async function (this: RealmContext) { + it("triggers an error and deletes the item if an item not matching the filter is created", async function (this: RealmContext) { await addSubscriptionAndSync(this.realm, this.realm.objects(FlexiblePersonSchema.name).filtered("age < 30")); - await expectClientResetError( + await expectInvalidWriteSyncError( this.config, this.user, (realm) => { @@ -1602,8 +1602,8 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () { ); }); - it("triggers a client reset if you remove a subscription without waiting for server acknowledgement, then modify objects that were only matched by the now removed subscription", async function (this: RealmContext) { - await expectClientResetError(this.config, this.user, async (realm) => { + it("triggers an error if you remove a subscription without waiting for server acknowledgement, then modify objects that were only matched by the now removed subscription", async function (this: RealmContext) { + await expectInvalidWriteSyncError(this.config, this.user, async (realm) => { const { sub } = await addSubscriptionForPersonAndSync(this.realm); this.realm.subscriptions.update((mutableSubs) => { diff --git a/integration-tests/tests/src/utils/expect-sync-error.ts b/integration-tests/tests/src/utils/expect-sync-error.ts index 3d3cef2ec7..b80edb0023 100644 --- a/integration-tests/tests/src/utils/expect-sync-error.ts +++ b/integration-tests/tests/src/utils/expect-sync-error.ts @@ -19,6 +19,8 @@ import { expect } from "chai"; import { openRealm } from "./open-realm"; +type Error = (Realm.SyncError | Realm.ClientResetError) & { message: string }; + /** * Open a new Realm and perform an action, expecting a sync error to occur. Will * never resolve and therefore timeout if a sync error does not occur. @@ -34,7 +36,7 @@ export async function expectSyncError( config: Realm.Configuration, user: Realm.User, action: (realm: Realm) => void, - expectation: (error: Realm.SyncError | Realm.ClientResetError) => void, + expectation: (error: Error) => void, ): Promise { let handleError: Realm.ErrorCallback | undefined; @@ -59,6 +61,34 @@ export async function expectSyncError( }); } +/** + * Expect a sync error to occur with a message about an invalid write. + * Optionally specify more expectations about the sync error. Will + * never resolve and therefore timeout if a sync error does not occur. + * + * @param config The Realm config to use + * @param user The Realm user to use + * @param action Callback receiving a Realm instance and containing the + * action(s) to take which should trigger a client reset error + * @param extraExpectation Optional callback receiving the sync error, in order to make more + * assertions about it + * @returns Promise which resolves if the sync error occurs + */ +export async function expectInvalidWriteSyncError( + config: Realm.Configuration, + user: Realm.User, + action: (realm: Realm) => void, + extraExpectation?: (error: Error) => void, +): Promise { + return expectSyncError(config, user, action, (error) => { + expect(error.name).to.equal("Error"); + expect(error.message).to.match( + /Client attempted a write that is outside of permissions or query filters; it has been reverted.*/, + ); + if (extraExpectation) extraExpectation(error); + }); +} + /** * Expect a client reset sync error to occur when performing an action. Optionally specify * more expectations about the sync error. Will never resolve and therefore timeout if a @@ -76,7 +106,7 @@ export async function expectClientResetError( config: Realm.Configuration, user: Realm.User, action: (realm: Realm) => void, - extraExpectation?: (error: Realm.SyncError | Realm.ClientResetError) => void, + extraExpectation?: (error: Error) => void, ): Promise { return expectSyncError(config, user, action, (error) => { expect(error.name).to.equal("ClientReset"); From 1c7f1fadc803c223e026c5f23cd7eed849ac26ad Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Thu, 2 Jun 2022 10:49:54 +0200 Subject: [PATCH 2/5] Update core --- CHANGELOG.md | 9 +++------ vendor/realm-core | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3746e09e..797c9ea152 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,8 @@ x.x.x Release notes (yyyy-MM-dd) * None. ### Fixed -* ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?) -* Add canonical schema type for returned schemas ([#4580](https://github.com/realm/realm-js/pull/4580)) -* Fixed invalid type for schema properties([#4577](https://github.com/realm/realm-js/pull/4577)). +* Add canonical schema type for returned schemas. ([#4580](https://github.com/realm/realm-js/pull/4580)) +* Fixed invalid type for schema properties. ([#4577](https://github.com/realm/realm-js/pull/4577)) ### Compatibility * MongoDB Realm Cloud. @@ -15,9 +14,7 @@ x.x.x Release notes (yyyy-MM-dd) * File format: generates Realms with format v22 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms). ### Internal -* -* -* +* Upgraded Realm Core from v12.0.0 to commit 91c5ac9180a3db68a27da3f46d36cb437a732f4d. 10.18.0 Release notes (2022-5-29) ============================================================= diff --git a/vendor/realm-core b/vendor/realm-core index 9e2f3cb730..91c5ac9180 160000 --- a/vendor/realm-core +++ b/vendor/realm-core @@ -1 +1 @@ -Subproject commit 9e2f3cb730a546ff33e95c563a85e3cf61f17d17 +Subproject commit 91c5ac9180a3db68a27da3f46d36cb437a732f4d From 37f918e8f00b28f6d4fb045bbf724a01d52c0343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 2 Jun 2022 11:48:20 +0200 Subject: [PATCH 3/5] Suggesting changes to make linting green --- .../tests/src/utils/expect-sync-error.ts | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/integration-tests/tests/src/utils/expect-sync-error.ts b/integration-tests/tests/src/utils/expect-sync-error.ts index b80edb0023..ead412a770 100644 --- a/integration-tests/tests/src/utils/expect-sync-error.ts +++ b/integration-tests/tests/src/utils/expect-sync-error.ts @@ -19,7 +19,7 @@ import { expect } from "chai"; import { openRealm } from "./open-realm"; -type Error = (Realm.SyncError | Realm.ClientResetError) & { message: string }; +type Error = Realm.SyncError | Realm.ClientResetError | { message: string }; /** * Open a new Realm and perform an action, expecting a sync error to occur. Will @@ -38,26 +38,28 @@ export async function expectSyncError( action: (realm: Realm) => void, expectation: (error: Error) => void, ): Promise { - let handleError: Realm.ErrorCallback | undefined; + return new Promise((resolve, reject) => { + if (!config.sync) { + throw new Error("Expected a sync config"); + } - const configWithErrorHandler = { ...config }; - if (!configWithErrorHandler.sync) { - throw new Error("Expected a sync config"); - } - - configWithErrorHandler.sync.error = (session, error) => { - if (handleError) handleError(session, error); - }; - - const { realm } = await openRealm(configWithErrorHandler, user); - - return new Promise((resolve) => { - handleError = (session, error) => { - expectation(error); - resolve(); + // Shallow copy the sync configuration to modifying the original + const modifiedConfig: Realm.Configuration = { + ...config, + sync: { + ...config.sync, + error(_, error) { + try { + expectation(error); + resolve(); + } catch (err) { + reject(err); + } + }, + }, }; - action(realm); + openRealm(modifiedConfig, user).then(({ realm }) => action(realm), reject); }); } From cac3f2c80f1d769c1173167efa581725ab803883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 2 Jun 2022 12:34:51 +0200 Subject: [PATCH 4/5] Fixed Error type --- integration-tests/tests/src/utils/expect-sync-error.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/tests/src/utils/expect-sync-error.ts b/integration-tests/tests/src/utils/expect-sync-error.ts index ead412a770..24efd2f9cc 100644 --- a/integration-tests/tests/src/utils/expect-sync-error.ts +++ b/integration-tests/tests/src/utils/expect-sync-error.ts @@ -19,7 +19,7 @@ import { expect } from "chai"; import { openRealm } from "./open-realm"; -type Error = Realm.SyncError | Realm.ClientResetError | { message: string }; +type Error = Realm.SyncError | (Realm.ClientResetError & { message: string }); /** * Open a new Realm and perform an action, expecting a sync error to occur. Will @@ -48,7 +48,7 @@ export async function expectSyncError( ...config, sync: { ...config.sync, - error(_, error) { + error(_, error: Error) { try { expectation(error); resolve(); From 8a1738d6db029bddd7a13bc003a876539389adbb Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Thu, 2 Jun 2022 12:48:24 +0200 Subject: [PATCH 5/5] Upgrade to Realm Core v12.1.0 --- CHANGELOG.md | 6 ++++-- integration-tests/tests/src/tests/sync/mixed.ts | 3 ++- vendor/realm-core | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 797c9ea152..fd135f498b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ x.x.x Release notes (yyyy-MM-dd) ============================================================= ### Enhancements -* None. +* Creating an object for a class that has no subscriptions opened for it will throw an exception. ([realm/realm-core#5488](https://github.com/realm/realm-core/pull/5488)) ### Fixed * Add canonical schema type for returned schemas. ([#4580](https://github.com/realm/realm-js/pull/4580)) * Fixed invalid type for schema properties. ([#4577](https://github.com/realm/realm-js/pull/4577)) +* FLX sync subscription state changes will now correctly be reported after sync progress is reported. ([realm/realm-core#5553](https://github.com/realm/realm-core/pull/5553), since v10.18.0) ### Compatibility * MongoDB Realm Cloud. @@ -14,7 +15,8 @@ x.x.x Release notes (yyyy-MM-dd) * File format: generates Realms with format v22 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms). ### Internal -* Upgraded Realm Core from v12.0.0 to commit 91c5ac9180a3db68a27da3f46d36cb437a732f4d. +* Upgraded Realm Core from v12.0.0 to v12.1.0. +* Fix for updated FLX sync error message. ([#4611](https://github.com/realm/realm-js/pull/4611)) 10.18.0 Release notes (2022-5-29) ============================================================= diff --git a/integration-tests/tests/src/tests/sync/mixed.ts b/integration-tests/tests/src/tests/sync/mixed.ts index 7f7c992962..e18e9adab1 100644 --- a/integration-tests/tests/src/tests/sync/mixed.ts +++ b/integration-tests/tests/src/tests/sync/mixed.ts @@ -70,7 +70,7 @@ function describeRoundtrip({ async function setupTest(realm: Realm) { if (flexibleSync) { - realm.subscriptions.update((mutableSubs) => { + await realm.subscriptions.update((mutableSubs) => { mutableSubs.add(realm.objects("MixedClass")); }); await realm.subscriptions.waitForSynchronization(); @@ -94,6 +94,7 @@ function describeRoundtrip({ }); it("writes", async function (this: RealmContext) { + this.timeout(6000); await setupTest(this.realm); this._id = new Realm.BSON.ObjectId(); diff --git a/vendor/realm-core b/vendor/realm-core index 91c5ac9180..fd48276f88 160000 --- a/vendor/realm-core +++ b/vendor/realm-core @@ -1 +1 @@ -Subproject commit 91c5ac9180a3db68a27da3f46d36cb437a732f4d +Subproject commit fd48276f88f3d55dbdcdc9e8cbf32541811d5865