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

Add tests of support types of partition values #3671

Closed
Closed
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: 6 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ start_server() {
else
echo "no existing stitch instance running in docker, attempting to start one"
. "${SRCROOT}/dependencies.list"
DOCKER_VOLUMES=""
for app in common-tests pv-int-tests pv-string-tests pv-uuid-tests pv-objectid-tests; do
DOCKER_VOLUMES="$DOCKER_VOLUMES -v ${SRCROOT}/tests/mongodb/${app}:/apps/${app}"
done
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}")
Comment on lines +76 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] I'd actually really like it if we can introduce an env variable that changes the local port we forward to the Docker image (e.g., MONGODB_REALM_PORT=9091).
makeAppConfig() seems to support this already using process.env.MONGODB_REALM_PORT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support the suggestion, but for testing on iOS/Android the task becomes less trivial, as the port would have to be passed to the test-app & Android need to have the port reversed. So I think out of scope, just now.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's other places in the script files that we provide a default if the environment variable isn't set, though.

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
1 change: 1 addition & 0 deletions tests/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if (global.enableSyncTests) {
TESTS.UserTests = require("./user-tests");
TESTS.SessionTests = require("./session-tests");
TESTS.UUIDSyncTests= node_require("./uuid-sync-tests");
TESTS.PvTests = node_require("./pv-tests.js");
}
}

Expand Down
218 changes: 218 additions & 0 deletions tests/js/pv-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
////////////////////////////////////////////////////////////////////////////
//
// 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';

/* global navigator, WorkerNavigator */

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?", // NOTE: this needs to be changed to non-optional in the docker image.
breed: "string?",
name: "string",
realm_id: "int?"
}
};

const PvStringDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image.
breed: "string?",
name: "string",
realm_id: "string?"
}
};

const PvUuidDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image.
breed: "string?",
name: "string",
realm_id: "uuid?"
}
};

const PvObjectidDog = {
name: "Dog",
primaryKey: "_id",
properties: {
_id: "objectId?", // NOTE: this needs to be changed to non-optional in the docker image.
breed: "string?",
name: "string",
realm_id: "objectId?"
}
};

module.exports = {
async testPvInt() {
let app = new Realm.App(AppConfig.pvIntAppConfig);

let credentials = Realm.Credentials.anonymous();
let user = await app.logIn(credentials);
const realmConfig = {
schema: [PvIntDog],
sync: {
user: user,
partitionValue: 42,
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close()
}
};

Realm.deleteFile(realmConfig);
let realm1 = await Realm.open(realmConfig);
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(realmConfig);

let realm2 = await Realm.open(realmConfig);
await realm2.syncSession.downloadAllServerChanges();

let dogs = realm2.objects("Dog");
TestCase.assertEqual(dogs.length, 1);

realm2.close();
await user.logOut();
},

async testPvString() {
let app = new Realm.App(AppConfig.pvStringAppConfig);

let credentials = Realm.Credentials.anonymous();
let user = await app.logIn(credentials);
const realmConfig = {
schema: [PvStringDog],
sync: {
user: user,
partitionValue: "42",
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close()
}
};

Realm.deleteFile(realmConfig);
let realm1 = await Realm.open(realmConfig);
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(realmConfig);

let realm2 = await Realm.open(realmConfig);
await realm2.syncSession.downloadAllServerChanges();

let dogs = realm2.objects("Dog");
TestCase.assertEqual(dogs.length, 1);

realm2.close();
await user.logOut();
},

/*async testUuidString() {
fronck marked this conversation as resolved.
Show resolved Hide resolved
let app = new Realm.App(AppConfig.pvUuidAppConfig);

let credentials = Realm.Credentials.anonymous();
let user = await app.logIn(credentials);
const realmConfig = {
schema: [PvUuidDog],
sync: {
user: user,
partitionValue: new UUID(),
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close()
}
};

Realm.deleteFile(realmConfig);
let realm1 = await Realm.open(realmConfig);
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(realmConfig);

let realm2 = await Realm.open(realmConfig);
await realm2.syncSession.downloadAllServerChanges();

let dogs = realm2.objects("Dog");
TestCase.assertEqual(dogs.length, 1);

realm2.close();
await user.logOut();
},*/

async testObjectidString() {
let app = new Realm.App(AppConfig.pvObjectidAppConfig);

let credentials = Realm.Credentials.anonymous();
let user = await app.logIn(credentials);
const realmConfig = {
schema: [PvObjectidDog],
sync: {
user: user,
partitionValue: new ObjectId(),
_sessionStopPolicy: "immediately", // Make it safe to delete files after realm.close()
}
};

Realm.deleteFile(realmConfig);
let realm1 = await Realm.open(realmConfig);
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(realmConfig);

let realm2 = await Realm.open(realmConfig);
await realm2.syncSession.downloadAllServerChanges();

let dogs = realm2.objects("Dog");
TestCase.assertEqual(dogs.length, 1);

realm2.close();
await user.logOut();
},
}
66 changes: 45 additions & 21 deletions tests/js/support/testConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,55 @@ function nodeRequire(module) {
return require_method(module);
}

let pathToStitchJson = "../../mongodb/config.json";
const isNodeProcess = typeof process === 'object' && process + '' === '[object process]';
function makeAppConfig(appId) {
const appUrl = process.env.MONGODB_REALM_ENDPOINT ? process.env.MONGODB_REALM_ENDPOINT.replace(/\"/g,'') : "http://localhost";
const appPort = process.env.MONGODB_REALM_PORT || "9090";

if (isNodeProcess && process.env.ELECTRON_TESTS_REALM_MODULE_PATH) {
const path = nodeRequire("path");
console.log("ELECTRON_TESTS_REALM_MODULE_PATH " + process.env.ELECTRON_TESTS_REALM_MODULE_PATH);
pathToStitchJson = path.resolve(process.env.ELECTRON_TESTS_REALM_MODULE_PATH, '../../../mongodb/config.json')
console.log(`tests are using integration tests app id: ${appId} on ${appUrl}:${appPort}`);

return {
id: appId,
url: `${appUrl}:${appPort}`,
timeout: 1000,
app: {
name: "default",
version: "0"
}
};
}

function getConfigPath(testName) {
let pathToJson = `../../mongodb/${testName}/config.json`;
const isNodeProcess = typeof process === 'object' && process + '' === '[object process]';

if (isNodeProcess && process.env.ELECTRON_TESTS_REALM_MODULE_PATH) {
const path = nodeRequire("path");
console.log("ELECTRON_TESTS_REALM_MODULE_PATH " + process.env.ELECTRON_TESTS_REALM_MODULE_PATH);
pathToStitchJson = path.resolve(process.env.ELECTRON_TESTS_REALM_MODULE_PATH, `../${pathToJson}`);
}
return pathToJson;
}
console.log("pathToStitchJson " + pathToStitchJson);

let pathToStitchJson = getConfigPath("common-tests");
const integrationTestsAppId = `${nodeRequire(pathToStitchJson).app_id}`;
const appUrl = process.env.MONGODB_REALM_ENDPOINT ? process.env.MONGODB_REALM_ENDPOINT.replace(/\"/g,'') : "http://localhost";
const appPort = process.env.MONGODB_REALM_PORT || "9090";
console.log(`tests are using integration tests app id: ${integrationTestsAppId} on ${appUrl}:${appPort}`);

const integrationAppConfig = {
id: integrationTestsAppId,
url: `${appUrl}:${appPort}`,
timeout: 1000,
app: {
name: "default",
version: '0'
},
};
const integrationAppConfig = makeAppConfig(integrationTestsAppId);

let pathToPvIntJSON = getConfigPath("pv-int-tests");
const pvIntTestsAppId = `${nodeRequire(pathToPvIntJSON).app_id}`;
const pvIntAppConfig = makeAppConfig(pvIntTestsAppId);

let pathToPvStringJSON = getConfigPath("pv-string-tests");
const pvStringTestsAppId = `${nodeRequire(pathToPvStringJSON).app_id}`;
const pvStringAppConfig = makeAppConfig(pvStringTestsAppId);

let pathToPvUuidJSON = getConfigPath("pv-uuid-tests");
const pvUuidTestsAppId = `${nodeRequire(pathToPvUuidJSON).app_id}`;
const pvUuidAppConfig = makeAppConfig(pvUuidTestsAppId);

let pathToPvObjectidJSON = getConfigPath("pv-objectid-tests");
const pvObjectidTestsAppId = `${nodeRequire(pathToPvObjectidJSON).app_id}`;
const pvObjectidAppConfig = makeAppConfig(pvObjectidTestsAppId);

module.exports = {
integrationAppConfig
integrationAppConfig, pvIntAppConfig, pvStringAppConfig, pvUuidAppConfig, pvObjectidAppConfig
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "6037be866c917b9bd04fb555",
"id": "606453b13d297b2d11f1d042",
"name": "anon-user",
"type": "anon-user",
"disabled": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "6037be866c917b9bd04fb556",
"id": "606453b13d297b2d11f1d043",
"name": "api-key",
"type": "api-key",
"disabled": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "6037be866c917b9bd04fb557",
"id": "606453b13d297b2d11f1d044",
"name": "custom-function",
"type": "custom-function",
"config": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "6037be866c917b9bd04fb558",
"id": "606453b13d297b2d11f1d045",
"name": "local-userpass",
"type": "local-userpass",
"config": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app_id": "auth-integration-tests-bhnql",
"app_id": "auth-integration-tests-uxnzd",
"config_version": 20200603,
"name": "auth-integration-tests",
"location": "US-VA",
Expand Down
3 changes: 3 additions & 0 deletions tests/mongodb/common-tests/environments/development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": {}
}
3 changes: 3 additions & 0 deletions tests/mongodb/common-tests/environments/no-environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": {}
}
3 changes: 3 additions & 0 deletions tests/mongodb/common-tests/environments/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": {}
}
3 changes: 3 additions & 0 deletions tests/mongodb/common-tests/environments/qa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": {}
}
3 changes: 3 additions & 0 deletions tests/mongodb/common-tests/environments/staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": {}
}
3 changes: 3 additions & 0 deletions tests/mongodb/common-tests/environments/testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"can_evaluate": {},
"id": "6037be866c917b9bd04fb551",
"id": "606453b13d297b2d11f1d03e",
"name": "authFunc",
"private": false
}
Loading