Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partition value tests (new test-server setup) #3677

Merged
merged 14 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,13 @@ def testLinux(target, postStep = null, Boolean enableSync = false) {
// see https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
// we refrain from using "latest" here to optimise docker pull cost due to a new image being built every day
// if there's really a new feature you need from the latest stitch, upgrade this manually
withRealmCloud(version: dependencies.MDBREALM_TEST_SERVER_TAG, appsToImport: ['auth-integration-tests': "${env.WORKSPACE}/tests/mongodb"]) { networkName ->
withRealmCloud(version: dependencies.MDBREALM_TEST_SERVER_TAG, appsToImport: [
'auth-integration-tests': "${env.WORKSPACE}/tests/mongodb/common-tests",
'pv-int-tests': "${env.WORKSPACE}/tests/mongodb/pv-int-tests",
'pv-string-tests': "${env.WORKSPACE}/tests/mongodb/pv-string-tests",
'pv-objectid-tests': "${env.WORKSPACE}/tests/mongodb/pv-objectid-tests",
'pv-uuid-tests': "${env.WORKSPACE}/tests/mongodb/pv-uuid-tests"
]) { networkName ->
buildSteps("-e MONGODB_REALM_ENDPOINT=\"http://mongodb-realm\" --network=${networkName}")
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ REALM_CORE_VERSION=10.1.4
REALM_SYNC_VERSION=10.1.6
NAPI_VERSION=4
OPENSSL_VERSION=1.1.1g
MDBREALM_TEST_SERVER_TAG=2021-02-10
MDBREALM_TEST_SERVER_TAG=2021-04-07
14 changes: 12 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,22 @@ start_server() {
else
echo "no existing stitch instance running in docker, attempting to start one"
. "${SRCROOT}/dependencies.list"
local stitch_apps_path="tests/mongodb"
DOCKER_VOLUMES=""
for app in $(ls -d $stitch_apps_path/*/ | cut -f3 -d'/'); do
local app_path="$stitch_apps_path/$app"
if [[ -f "$app_path/config.json" ]]; then
echo "Mounting folder '$app_path' as Stitch app."
DOCKER_VOLUMES="$DOCKER_VOLUMES -v ${SRCROOT}/${app_path}:/apps/${app}"
fi
done
echo "DOCKER_VOLUMES: $DOCKER_VOLUMES"
echo "using object-store stitch dependency: ${MDBREALM_TEST_SERVER_TAG}"
if [[ -n "$RUN_STITCH_IN_FORGROUND" ]]; then
# we don't worry about tracking the STITCH_DOCKER_ID because without the -d flag, this docker is tied to the shell
docker run -v "${SRCROOT}/tests/mongodb:/apps/os-integration-tests" -p 9090:9090 -it "docker.pkg.github.com/realm/ci/mongodb-realm-test-server:${MDBREALM_TEST_SERVER_TAG}"
docker run $DOCKER_VOLUMES -p 9090:9090 -it "docker.pkg.github.com/realm/ci/mongodb-realm-test-server:${MDBREALM_TEST_SERVER_TAG}"
else
STITCH_DOCKER_ID=$(docker run -d $BACKGROUND_FLAG -v "${SRCROOT}/tests/mongodb:/apps/os-integration-tests" -p 9090:9090 -it "docker.pkg.github.com/realm/ci/mongodb-realm-test-server:${MDBREALM_TEST_SERVER_TAG}")
STITCH_DOCKER_ID=$(docker run -d $BACKGROUND_FLAG $DOCKER_VOLUMES -p 9090:9090 -it "docker.pkg.github.com/realm/ci/mongodb-realm-test-server:${MDBREALM_TEST_SERVER_TAG}")
echo "starting docker image $STITCH_DOCKER_ID"
# wait for stitch to import apps and start serving before continuing
docker logs --follow "$STITCH_DOCKER_ID" | grep -m 1 "Serving on.*9090" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/js/app-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const require_method = require;

const Realm = require('realm');
const TestCase = require('./asserts');
const AppConfig = require('./support/testConfig')
const AppConfig = require('./support/testConfig');
const Utils = require('./test-utils');
const schemas = require('./schemas');

Expand Down
2 changes: 1 addition & 1 deletion tests/js/download-api-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function createObjects(user) {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId?",
_id: "objectId",
breed: "string?",
name: "string",
realm_id: "string?",
Expand Down
1 change: 1 addition & 0 deletions tests/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if (global.enableSyncTests) {
TESTS.UserTests = require("./user-tests");
TESTS.SessionTests = require("./session-tests");
TESTS.UUIDSyncTests= node_require("./uuid-sync-tests");
TESTS.PartitionValueTests = node_require("./partition-value-tests");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/js/mixed-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = {
name: "MixedObject",
primaryKey: "_id",
properties: {
_id: "objectId?",
_id: "objectId",
key: "string",
value: "mixed"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/js/nested-list-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ schemas.ParentObject = {
name: 'ParentObject',
primaryKey: '_id',
properties: {
_id: 'objectId?',
_id: 'objectId',
id: 'int',
name: 'NameObject[]'
}
Expand All @@ -27,7 +27,7 @@ schemas.NameObject = {
name: 'NameObject',
primaryKey: '_id',
properties: {
_id: 'objectId?',
_id: 'objectId',
family: 'string',
given: 'string[]',
prefix: 'string[]'
Expand Down
239 changes: 239 additions & 0 deletions tests/js/partition-value-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2021 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

"use strict";

const require_method = require;

const Realm = require("realm");
const TestCase = require("./asserts");
const AppConfig = require("./support/testConfig");
const { ObjectId, UUID } = Realm.BSON;

const PvIntDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId",
breed: "string?",
name: "string",
realm_id: "int?"
}
};

const PvStringDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId",
breed: "string?",
name: "string",
realm_id: "string?"
}
};

const PvUuidDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId",
breed: "string?",
name: "string",
realm_id: "uuid?"
}
};

const PvObjectIdDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId",
breed: "string?",
name: "string",
realm_id: "objectId?"
}
};

const createConfig = (schema, user, partitionValue) => ({
schema: Array.isArray(schema) ? schema : [schema],
sync: {
user,
partitionValue,
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close()
}
});

module.exports = {
async testPartitionValueAsInt() {
const app = new Realm.App(AppConfig.pvIntAppConfig);
const user = await app.logIn(Realm.Credentials.anonymous());

const realmConfigPrimary = createConfig(PvIntDog, user, 42);
const realmConfigSecondary = createConfig(PvIntDog, user, 43);

// ensure clean starting point
Realm.deleteFile(realmConfigPrimary);

const realm1 = await Realm.open(realmConfigPrimary);
realm1.write(() => {
realm1.create("Dog", { _id: new ObjectId(), name: "King" });
});

await realm1.syncSession.uploadAllLocalChanges();
TestCase.assertEqual(realm1.objects("Dog").length, 1);
realm1.close();

// cleanup, re-sync & check changes are synced
Realm.deleteFile(realmConfigPrimary);

const realm2 = await Realm.open(realmConfigPrimary);
await realm2.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm2.objects("Dog").length, 1);
realm2.close();

// cleanup & re-sync with different partitionValue
Realm.deleteFile(realmConfigPrimary);

const realm3 = await Realm.open(realmConfigSecondary);
await realm3.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm3.objects("Dog").length, 0);
realm3.close();

await user.logOut();
},

async testPartitionValueAsString() {
const app = new Realm.App(AppConfig.pvStringAppConfig);
const user = await app.logIn(Realm.Credentials.anonymous());

const realmConfigPrimary = createConfig(PvStringDog, user, "42");
const realmConfigSecondary = createConfig(PvStringDog, user, "43");

// ensure clean starting point
Realm.deleteFile(realmConfigPrimary);

const realm1 = await Realm.open(realmConfigPrimary);
realm1.write(() => {
realm1.create("Dog", { _id: new ObjectId(), name: "King" });
});

await realm1.syncSession.uploadAllLocalChanges();
TestCase.assertEqual(realm1.objects("Dog").length, 1);
realm1.close();

// cleanup, re-sync & check changes are synced
Realm.deleteFile(realmConfigPrimary);

const realm2 = await Realm.open(realmConfigPrimary);
await realm2.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm2.objects("Dog").length, 1);
realm2.close();

// cleanup & re-sync with different partitionValue
Realm.deleteFile(realmConfigPrimary);

const realm3 = await Realm.open(realmConfigSecondary);
await realm3.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm3.objects("Dog").length, 0);
realm3.close();

await user.logOut();
},

async testPartitionValueAsUuid() {
const app = new Realm.App(AppConfig.pvUuidAppConfig);
const user = await app.logIn(Realm.Credentials.anonymous());

const realmConfigPrimary = createConfig(PvUuidDog, user, new UUID("57eade47-8406-4397-ab97-49abcc4d681f"));
const realmConfigSecondary = createConfig(PvUuidDog, user, new UUID("90d82df4-6037-4eb6-869b-a62f7af522b0"));

// ensure clean starting point
Realm.deleteFile(realmConfigPrimary);

const realm1 = await Realm.open(realmConfigPrimary);
realm1.write(() => {
realm1.create("Dog", { _id: new ObjectId(), name: "King" });
});

await realm1.syncSession.uploadAllLocalChanges();
TestCase.assertEqual(realm1.objects("Dog").length, 1);
realm1.close();

// cleanup, re-sync & check changes are synced
Realm.deleteFile(realmConfigPrimary);

const realm2 = await Realm.open(realmConfigPrimary);
await realm2.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm2.objects("Dog").length, 1);
realm2.close();

// cleanup & re-sync with different partitionValue
Realm.deleteFile(realmConfigPrimary);

const realm3 = await Realm.open(realmConfigSecondary);
await realm3.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm3.objects("Dog").length, 0);
realm3.close();

await user.logOut();
},

async testPartitionValueAsObjectId() {
const app = new Realm.App(AppConfig.pvObjectidAppConfig);
const user = await app.logIn(Realm.Credentials.anonymous());

const realmConfigPrimary = createConfig(PvObjectIdDog, user, new ObjectId("606d8cdf33e41d1409245e60"));
const realmConfigSecondary = createConfig(PvObjectIdDog, user, new ObjectId("606d8cdf33e41d1409245e63"));

// ensure clean starting point
Realm.deleteFile(realmConfigPrimary);
const realm1 = await Realm.open(realmConfigPrimary);
realm1.write(() => {
realm1.create("Dog", { _id: new ObjectId(), name: "King" });
});

await realm1.syncSession.uploadAllLocalChanges();
TestCase.assertEqual(realm1.objects("Dog").length, 1);
realm1.close();

Realm.deleteFile(realmConfigPrimary);

const realm2 = await Realm.open(realmConfigPrimary);
await realm2.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm2.objects("Dog").length, 1);
realm2.close();

// cleanup & re-sync with different partitionValue
Realm.deleteFile(realmConfigPrimary);

const realm3 = await Realm.open(realmConfigSecondary);
await realm3.syncSession.downloadAllServerChanges();

TestCase.assertEqual(realm3.objects("Dog").length, 0);
realm3.close();

await user.logOut();
},
}
Loading