diff --git a/.github/workflows/pr-realm-js.yml b/.github/workflows/pr-realm-js.yml index 7a9c3cf1f8..a2a4210110 100644 --- a/.github/workflows/pr-realm-js.yml +++ b/.github/workflows/pr-realm-js.yml @@ -59,20 +59,20 @@ jobs: fail-fast: false matrix: variant: - - { os: linux, runner: ubuntu-latest, arch: x64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } - - { os: linux, runner: ubuntu-latest, arch: arm, artifact-path: packages/realm/prebuilds } - - { os: linux, runner: ubuntu-latest, arch: arm64, artifact-path: packages/realm/prebuilds } - - { os: windows, runner: windows-latest, arch: x64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } - - { os: windows, runner: windows-2019, arch: ia32, artifact-path: packages/realm/prebuilds } - - { os: android, runner: ubuntu-latest, arch: x86_64, artifact-path: packages/realm/react-native/android/src/main/jniLibs } - - { os: android, runner: ubuntu-latest, arch: armeabi-v7a, artifact-path: packages/realm/react-native/android/src/main/jniLibs } - - { os: android, runner: ubuntu-latest, arch: arm64-v8a, artifact-path: packages/realm/react-native/android/src/main/jniLibs } - - { os: android, runner: ubuntu-latest, arch: x86, artifact-path: packages/realm/react-native/android/src/main/jniLibs } + # - { os: linux, runner: ubuntu-latest, arch: x64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } + # - { os: linux, runner: ubuntu-latest, arch: arm, artifact-path: packages/realm/prebuilds } + # - { os: linux, runner: ubuntu-latest, arch: arm64, artifact-path: packages/realm/prebuilds } + # - { os: windows, runner: windows-latest, arch: x64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } + # - { os: windows, runner: windows-2019, arch: ia32, artifact-path: packages/realm/prebuilds } + # - { os: android, runner: ubuntu-latest, arch: x86_64, artifact-path: packages/realm/react-native/android/src/main/jniLibs } + # - { os: android, runner: ubuntu-latest, arch: armeabi-v7a, artifact-path: packages/realm/react-native/android/src/main/jniLibs } + # - { os: android, runner: ubuntu-latest, arch: arm64-v8a, artifact-path: packages/realm/react-native/android/src/main/jniLibs } + # - { os: android, runner: ubuntu-latest, arch: x86, artifact-path: packages/realm/react-native/android/src/main/jniLibs } - { os: darwin, runner: macos-latest, arch: x64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } - - { os: darwin, runner: macos-latest, arch: arm64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } - - { os: ios, runner: macos-latest-xlarge, arch: simulator, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework } - - { os: ios, runner: macos-latest-xlarge, arch: catalyst, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework } - - { os: ios, runner: macos-latest-xlarge, arch: ios, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework } + # - { os: darwin, runner: macos-latest, arch: arm64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true } + # - { os: ios, runner: macos-latest-xlarge, arch: simulator, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework } + # - { os: ios, runner: macos-latest-xlarge, arch: catalyst, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework } + # - { os: ios, runner: macos-latest-xlarge, arch: ios, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework } steps: - name: Checkout code uses: actions/checkout@v3 @@ -215,7 +215,7 @@ jobs: ios-xcframework: name: Generate Info.plist with all frameworks in place needs: [build] - if: ${{ success() || failure() }} + if: ${{ false }} runs-on: macos-latest steps: - name: Checkout code @@ -243,7 +243,7 @@ jobs: integration-tests: name: Test ${{ matrix.variant.environment }} on ${{ matrix.variant.os }} (${{matrix.variant.target}}) - needs: [bundle, build, ios-xcframework] + needs: [bundle, build] if: ${{ success() || failure() }} env: REALM_DISABLE_ANALYTICS: 1 @@ -261,18 +261,18 @@ jobs: fail-fast: false matrix: variant: - - { os: linux, target: "test:ci", runner: ubuntu-latest, environment: node } - - { os: linux, target: "test:ci:main", runner: ubuntu-latest, environment: electron } - - { os: linux, target: "test:ci:renderer", runner: ubuntu-latest, environment: electron } - #- { os: windows, target: "test:ci", runner: windows-latest, environment: node} - #- { os: windows, target: "test:ci:main", runner: windows-latest, environment: electron } - #- { os: windows, target: "test:ci:renderer", runner: windows-latest, environment: electron } + # - { os: linux, target: "test:ci", runner: ubuntu-latest, environment: node } + # - { os: linux, target: "test:ci:main", runner: ubuntu-latest, environment: electron } + # - { os: linux, target: "test:ci:renderer", runner: ubuntu-latest, environment: electron } + # #- { os: windows, target: "test:ci", runner: windows-latest, environment: node} + # #- { os: windows, target: "test:ci:main", runner: windows-latest, environment: electron } + # #- { os: windows, target: "test:ci:renderer", runner: windows-latest, environment: electron } - { os: darwin, target: "test:ci:main", runner: macos-latest, environment: electron } - - { os: darwin, target: "test:ci:renderer", runner: macos-latest, environment: electron } - - { os: darwin, target: "test:ci", runner: macos-latest, environment: node } - - { os: android, target: "test:ci:android", runner: macos-latest-large, environment: react-native, arch: "armeabi-v7a" } - - { os: ios, target: "test:ci:ios", runner: macos-latest-xlarge, environment: react-native, arch: "ios" } - #- { os: ios, target: "test:ci:catalyst", runner: macos-latest, environment: react-native, arch: "catalyst" } + # - { os: darwin, target: "test:ci:renderer", runner: macos-latest, environment: electron } + # - { os: darwin, target: "test:ci", runner: macos-latest, environment: node } + # - { os: android, target: "test:ci:android", runner: macos-latest-large, environment: react-native, arch: "armeabi-v7a" } + # - { os: ios, target: "test:ci:ios", runner: macos-latest-xlarge, environment: react-native, arch: "ios" } + # #- { os: ios, target: "test:ci:catalyst", runner: macos-latest, environment: react-native, arch: "catalyst" } timeout-minutes: 60 steps: - name: Checkout code diff --git a/integration-tests/tests/src/tests/sync/sync-session.ts b/integration-tests/tests/src/tests/sync/sync-session.ts index b0301741b0..30d488b129 100644 --- a/integration-tests/tests/src/tests/sync/sync-session.ts +++ b/integration-tests/tests/src/tests/sync/sync-session.ts @@ -912,184 +912,186 @@ describe.skipIf(environment.missingServer, "SessionTest", () => { expect(encryptedRealmCopy).to.be.undefined; }); - it("has expected behaviour", async function (this: AppContext) { - this.longTimeout(); - const credentials1 = await getRegisteredEmailPassCredentials(this.app); - const credentials2 = await getRegisteredEmailPassCredentials(this.app); - const credentials3 = await getRegisteredEmailPassCredentials(this.app); - const partition = generatePartition(); - - /* + for (let i = 0; i < 50; i++) { + it.only("has expected behaviour " + i, async function (this: AppContext) { + this.longTimeout(); + const credentials1 = await getRegisteredEmailPassCredentials(this.app); + const credentials2 = await getRegisteredEmailPassCredentials(this.app); + const credentials3 = await getRegisteredEmailPassCredentials(this.app); + const partition = generatePartition(); + + /* Test 1: check whether calls to `writeCopyTo` are allowed at the right times */ - let user1 = await this.app.logIn(credentials1); - const config1: Realm.Configuration = { - sync: { - user: user1, - partitionValue: partition, - //@ts-expect-error internal field - _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() - }, - schema: [PersonForSyncSchema, DogForSyncSchema], - }; - - const realm1 = await Realm.open(config1); - const realm1Path = realm1.path; + let user1 = await this.app.logIn(credentials1); + const config1: Realm.Configuration = { + sync: { + user: user1, + partitionValue: partition, + //@ts-expect-error internal field + _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() + }, + schema: [PersonForSyncSchema, DogForSyncSchema], + }; - realm1.write(() => { - for (let i = 0; i < 25; i++) { - realm1.create("Person", { - _id: new BSON.ObjectId(), - age: i, - firstName: "John", - lastName: "Smith", - partition, - }); - } - }); + const realm1 = await Realm.open(config1); + const realm1Path = realm1.path; + + realm1.write(() => { + for (let i = 0; i < 25; i++) { + realm1.create("Person", { + _id: new BSON.ObjectId(), + age: i, + firstName: "John", + lastName: "Smith", + partition, + }); + } + }); - await realm1.syncSession?.uploadAllLocalChanges(); - await realm1.syncSession?.downloadAllServerChanges(); + await realm1.syncSession?.uploadAllLocalChanges(); + await realm1.syncSession?.downloadAllServerChanges(); - const outputConfig1 = { - schema: [PersonForSyncSchema, DogForSyncSchema], - path: realm1Path + "copy1.realm", - }; - // changes are synced -- we should be able to copy the realm - realm1.writeCopyTo(outputConfig1); + const outputConfig1 = { + schema: [PersonForSyncSchema, DogForSyncSchema], + path: realm1Path + "copy1.realm", + }; + // changes are synced -- we should be able to copy the realm + realm1.writeCopyTo(outputConfig1); + + // log out the user that created the realm + await user1.logOut(); + + realm1.syncSession?.pause(); + + // add another 2500 people + realm1.write(() => { + for (let i = 0; i < 2500; i++) { + realm1.create("Person", { + _id: new BSON.ObjectId(), + age: i, + firstName: "John", + lastName: "Smith", + partition, + }); + } + }); - // log out the user that created the realm - await user1.logOut(); + // Log user back in to attempt to copy synced changes + user1 = await this.app.logIn(credentials1); + const realm2Path = `${realm1Path}copy2.realm`; + const outputConfig2: Realm.Configuration = { + sync: { + user: user1, + partitionValue: partition, + //@ts-expect-error internal field + _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() + }, + schema: [PersonForSyncSchema, DogForSyncSchema], + path: realm2Path, + }; - realm1.syncSession?.pause(); + // we haven't uploaded our recent changes -- we're not allowed to copy + expect(() => { + realm1.writeCopyTo(outputConfig2); + }).throws("All client changes must be integrated in server before writing copy"); - // add another 2500 people - realm1.write(() => { - for (let i = 0; i < 2500; i++) { - realm1.create("Person", { - _id: new BSON.ObjectId(), - age: i, - firstName: "John", - lastName: "Smith", - partition, - }); - } - }); + // log back in and upload the changes we made locally + realm1.syncSession?.resume(); + user1 = await this.app.logIn(credentials1); + await realm1.syncSession?.uploadAllLocalChanges(); - // Log user back in to attempt to copy synced changes - user1 = await this.app.logIn(credentials1); - const realm2Path = `${realm1Path}copy2.realm`; - const outputConfig2: Realm.Configuration = { - sync: { - user: user1, - partitionValue: partition, - //@ts-expect-error internal field - _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() - }, - schema: [PersonForSyncSchema, DogForSyncSchema], - path: realm2Path, - }; - - // we haven't uploaded our recent changes -- we're not allowed to copy - expect(() => { + // create copy no. 2 of the realm realm1.writeCopyTo(outputConfig2); - }).throws("All client changes must be integrated in server before writing copy"); - - // log back in and upload the changes we made locally - realm1.syncSession?.resume(); - user1 = await this.app.logIn(credentials1); - await realm1.syncSession?.uploadAllLocalChanges(); - - // create copy no. 2 of the realm - realm1.writeCopyTo(outputConfig2); - /* + /* Test 2: check that a copied realm can be opened by another user, and that the contents of the original realm and the copy are as expected */ - // log in a new user, open the realm copy we created just above - const user2 = await this.app.logIn(credentials2); - const config2: Realm.Configuration = { - sync: { - user: user2, - partitionValue: partition, - //@ts-expect-error internal field - _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() - }, - schema: [PersonForSyncSchema, DogForSyncSchema], - path: realm2Path, - }; - - const realm2 = await Realm.open(config2); - - let realm1Persons = realm1.objects("Person"); - let realm2Persons = realm2.objects("Person"); - expect(realm1Persons.length).equals( - realm2Persons.length, - "The same number of people should be in the two realms", - ); + // log in a new user, open the realm copy we created just above + const user2 = await this.app.logIn(credentials2); + const config2: Realm.Configuration = { + sync: { + user: user2, + partitionValue: partition, + //@ts-expect-error internal field + _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() + }, + schema: [PersonForSyncSchema, DogForSyncSchema], + path: realm2Path, + }; - // add another 25 people locally to the original realm - realm1.syncSession?.pause(); - realm1.write(() => { - for (let i = 0; i < 25; i++) { - realm1.create("Person", { - _id: new BSON.ObjectId(), - age: i, - firstName: "John", - lastName: "Smith", - partition, - }); - } - }); + const realm2 = await Realm.open(config2); + + let realm1Persons = realm1.objects("Person"); + let realm2Persons = realm2.objects("Person"); + expect(realm1Persons.length).equals( + realm2Persons.length, + "The same number of people should be in the two realms", + ); + + // add another 25 people locally to the original realm + realm1.syncSession?.pause(); + realm1.write(() => { + for (let i = 0; i < 25; i++) { + realm1.create("Person", { + _id: new BSON.ObjectId(), + age: i, + firstName: "John", + lastName: "Smith", + partition, + }); + } + }); - realm1Persons = realm1.objects("Person"); - realm2Persons = realm2.objects("Person"); - expect(realm1Persons.length).equals(realm2Persons.length + 25, "realm1 should have an additional 25 people"); - realm1.syncSession?.resume(); + realm1Persons = realm1.objects("Person"); + realm2Persons = realm2.objects("Person"); + expect(realm1Persons.length).equals(realm2Persons.length + 25, "realm1 should have an additional 25 people"); + realm1.syncSession?.resume(); - await realm1.syncSession?.uploadAllLocalChanges(); - await realm1.syncSession?.downloadAllServerChanges(); + await realm1.syncSession?.uploadAllLocalChanges(); + await realm1.syncSession?.downloadAllServerChanges(); - await user2.logOut(); - realm2.close(); - Realm.deleteFile(config2); + await user2.logOut(); + realm2.close(); + Realm.deleteFile(config2); - /* + /* Test 3: open a copy of our realm with a new user and a new partition key. We expect it to fail because of the mismatch in partition keys */ - const realm3Path = realm1Path + "copy3.realm"; - const outputConfig3 = { ...config1, path: realm3Path }; - realm1.writeCopyTo(outputConfig3); - - const user3 = await this.app.logIn(credentials3); - const otherPartition = generatePartition(); - const config3: Realm.Configuration = { - sync: { - user: user3, - partitionValue: otherPartition, - //@ts-expect-error internal field - _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() - clientReset: { - mode: "manual", - onManual: (...args) => console.log("error", args), + const realm3Path = realm1Path + "copy3.realm"; + const outputConfig3 = { ...config1, path: realm3Path }; + realm1.writeCopyTo(outputConfig3); + + const user3 = await this.app.logIn(credentials3); + const otherPartition = generatePartition(); + const config3: Realm.Configuration = { + sync: { + user: user3, + partitionValue: otherPartition, + //@ts-expect-error internal field + _sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close() + clientReset: { + mode: "manual", + onManual: (...args) => console.log("error", args), + }, }, - }, - schema: [PersonForSyncSchema, DogForSyncSchema], - path: realm3Path, - }; + schema: [PersonForSyncSchema, DogForSyncSchema], + path: realm3Path, + }; - let realm3; - try { - realm3 = await Realm.open(config3); - throw new Error("successfully opened invalid realm"); - } catch (e: any) { - expect(e.message).contains("Bad server version"); - } + let realm3; + try { + realm3 = await Realm.open(config3); + throw new Error("successfully opened invalid realm"); + } catch (e: any) { + expect(e.message).contains("Bad server version"); + } - expect(realm3).to.be.undefined; - }); + expect(realm3).to.be.undefined; + }); + } }); });