Skip to content

Commit

Permalink
Enable all tests after bad rebase (#5595)
Browse files Browse the repository at this point in the history
* Importing all tests

* Temporarily skipping "open-behavior" as they crash

* Updating error messages to match the new SDK

* Throw when setting length of Results

* Correct error when assigning to OrderedCollection

* Updated tests to use new error codes

See https://github.com/realm/realm-core/blob/13ce20f6b94d8e0686882378f7e3a35d322a4600/src/realm/error_codes.h#L180

* Adding a missing Realm import

* Re-arming the Realm.open tests

* Cancel unresolved tasks when clearing test state

The bindgen SDK's variant of #5436

Removed ProgressRealmPromise.cancelUnresolvedTasks

Reference task only if it isn't resat

* Clear test state after compensating writes test

* Moved clearTestState up

* nit

* Using isValid to assert object deletion

* Adding a fast-track for common types

* Convert typed arrays to arraybuffer

* Fixing nested lists test

* Fixing api-key client test

* Fixed timeout test

* Fixing test to avoid mutating object schema when normalizing

* Fixed flexible sync clearTestState

* Fixed ProgressRealmPromise TSR race

* Fixed invalid sync config tests

* Made PromiseHandle directly awaitable and tested

* Renamed "RealmListeners#callback" to "notify"

* Spreading RealmListeners#listeners when notifying

This avoids firing listeners that gets added from other listeners

* Fixed linkingObjects assert

* Fixed "Bad changeset (UPLOAD)" by passing partition

* Asserting a valid object after thrown from defaultGet and defaultSet

* Updated type asserts on OrderedCollection#sorted

* Updated expected message from prohibited upgrades

* Adding ORG_GRADLE_PROJECT_* to test:android

* Fix bigIntToI64 and bigIntToU64 on JSC

* Throw from _objectForObjectKey if objectKey is not numeric

* Transform colKey to string before storing and looking it up

* Made stackTrace test less platform dependent

* Update integration-tests/tests/src/tests.ts

Co-authored-by: LJ <[email protected]>

* Update integration-tests/tests/src/tests/sync/sync-session.ts

Co-authored-by: LJ <[email protected]>

* Apply suggestions from code review

Co-authored-by: LJ <[email protected]>

---------

Co-authored-by: LJ <[email protected]>
  • Loading branch information
kraenhansen and elle-j authored Apr 5, 2023
1 parent 45dd275 commit 7600aea
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 217 deletions.
8 changes: 7 additions & 1 deletion integration-tests/environments/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@
],
"env": {
"PLATFORM": "android",
"WATCH": "false"
"WATCH": "false",
"ORG_GRADLE_PROJECT_newArchEnabled": {
"external": true
},
"ORG_GRADLE_PROJECT_hermesEnabled": {
"external": true
}
}
},
"test:ios": {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ afterEach(() => {

import "./utils/import-app.test.ts";
import "./utils/chai-plugin.test.ts";
import "./utils/promise-handle.test.ts";
import "./mocha-internals.test.ts";

import "./tests";
Expand Down
22 changes: 20 additions & 2 deletions integration-tests/tests/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,45 @@ import "./tests/credentials/jwt";
import "./tests/sync/app";
import "./tests/sync/asymmetric";
import "./tests/sync/client-reset";
import "./tests/sync/dictionary";
import "./tests/sync/encryption";
import "./tests/sync/flexible";
import "./tests/sync/mixed";
import "./tests/sync/sync-as-local";
import "./tests/sync/upload-delete-download";
import "./tests/sync/mongo-db-client";
import "./tests/sync/open-behavior";
import "./tests/sync/open";
import "./tests/sync/partition-values";
import "./tests/sync/realm-conversions";
import "./tests/sync/realm";
import "./tests/sync/set";
import "./tests/sync/sync-as-local";
import "./tests/sync/sync-session";
import "./tests/sync/upload-delete-download";
import "./tests/sync/user";
import "./tests/sync/uuid";

import "./tests/alias";
import "./tests/array-buffer";
import "./tests/bson";
import "./tests/class-models";
import "./tests/dictionary";
import "./tests/dynamic-schema-updates";
import "./tests/enums";
import "./tests/iterators";
import "./tests/linking-objects";
import "./tests/list";
import "./tests/listeners";
import "./tests/migrations";
import "./tests/mixed";
import "./tests/notifications";
import "./tests/objects";
import "./tests/queries";
import "./tests/realm-constructor";
import "./tests/results";
import "./tests/schema";
import "./tests/serialization";
import "./tests/set";
import "./tests/sets";
import "./tests/shared-realms";
import "./tests/transaction";
import "./tests/types";
2 changes: 1 addition & 1 deletion integration-tests/tests/src/tests/array-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ describe("ArrayBuffer type", () => {
it("handles wrong input", function (this: RealmContext) {
expect(() => {
this.realm.write(() => this.realm.create(SingleSchema.name, { a: {} }));
}).throws(Error, "PrimitiveData.a must be of type 'binary?', got 'object' ([object Object])");
}).throws("Expected value to be an instance of ArrayBuffer, got an object");
});
});
9 changes: 3 additions & 6 deletions integration-tests/tests/src/tests/linking-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,13 @@ describe("Linking objects", () => {
person = this.realm.create<IPersonSchema>(PersonSchema.name, { name: "Person 1", age: 50 });
});
expect(() => person.linkingObjects("NoSuchSchema", "noSuchProperty")).throws(
Error,
"Could not find schema for type 'NoSuchSchema'",
"Object type 'NoSuchSchema' not found in schema.",
);
expect(() => person.linkingObjects("PersonObject", "noSuchProperty")).throws(
Error,
"Type 'PersonObject' does not contain property 'noSuchProperty'",
"Property 'noSuchProperty' does not exist on 'PersonObject' objects",
);
expect(() => person.linkingObjects("PersonObject", "name")).throws(
Error,
"'PersonObject.name' is not a relationship to 'PersonObject'",
"'PersonObject#name' is not a relationship to 'PersonObject'",
);
let olivier: Person;
let oliviersParents: Realm.Results<IPersonSchema>;
Expand Down
14 changes: 10 additions & 4 deletions integration-tests/tests/src/tests/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1838,10 +1838,10 @@ describe("Lists", () => {
});

// Test that we can push a created object on a list
const name = this.realm.create<INameObjectSchema>(NameObjectLocalSchema.name, {
const name = this.realm.create<INameObjectSchema>(NameObjectSchema.name, {
_id: new BSON.ObjectId(),
family: "Petersen",
given: ["Gurli", "Margrete"],
family: "Larsen",
given: ["Lars"],
prefix: [],
});
const person = this.realm.create<IParentObjectSchema>(ParentObjectSchema.name, {
Expand All @@ -1853,7 +1853,7 @@ describe("Lists", () => {
});

const objects = this.realm.objects<IParentObjectSchema>(ParentObjectSchema.name).sorted([["id", false]]);
expect(objects.length).equals(2);
expect(objects.length).equals(3);
expect(objects[0].name.length).equals(2);
expect(objects[0].name[0].given.length).equals(2);
expect(objects[0].name[0].prefix.length).equals(0);
Expand All @@ -1868,6 +1868,12 @@ describe("Lists", () => {
expect(objects[1].name[0].prefix.length).equals(0);
expect(objects[1].name[0].given[0]).equals("Gurli");
expect(objects[1].name[0].given[1]).equals("Margrete");

expect(objects[2].name.length).equals(1);
expect(objects[2].name[0].given.length).equals(1);
expect(objects[2].name[0].prefix.length).equals(0);
expect(objects[2].name[0].given[0]).equals("Lars");
expect(objects[2].name[0].family).equals("Larsen");
});
it("supports nested lists from parsed JSON", function (this: RealmContext) {
const json =
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/src/tests/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("Migrations", () => {
expect(function () {
//@ts-expect-error This is an invalid function.
new Realm({ schema: [], schemaVersion: 2, onMigration: "invalid", inMemory: true });
}).throws("onMigration must be of type 'function'");
}).throws("Expected 'onMigration' on realm configuration to be a function, got a string");
});

it("should propogate exceptions", () => {
Expand Down Expand Up @@ -437,7 +437,7 @@ describe("Migrations", () => {
expect(() => {
// Deleting a model which is target of linkingObjects results in an exception
newRealm.deleteModel("Person");
}).throws("Table is target of cross-table link columns");
}).throws("Cannot remove class_Person that is target of outside links");
},
});

Expand Down
11 changes: 6 additions & 5 deletions integration-tests/tests/src/tests/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,9 @@ describe("Realm.Object", () => {
this.realm.delete(obj);
expect(obj.isValid()).to.be.false;
// Reading a column from deleted object should fail
expect(() => obj.doubleCol).to.throw("No object with key");
expect(() => obj.doubleCol).to.throw("Accessing object which has been invalidated or deleted");
// Writing to a column from deleted object should fail
expect(() => (obj.doubleCol = 0)).to.throw("No object with key");
expect(() => (obj.doubleCol = 0)).to.throw("Accessing object which has been invalidated or deleted");
return obj;
});

Expand Down Expand Up @@ -1113,10 +1113,11 @@ describe("Realm.Object", () => {
const freeKey = obj._objectKey();
//@ts-expect-error uses private method.
const obj1 = this.realm._objectForObjectKey(AgeSchema.name, "1" + freeKey);
//@ts-expect-error uses private method.
const obj2 = this.realm._objectForObjectKey(AgeSchema.name, "invalid int64_t");
expect(obj1).to.be.undefined;
expect(obj2).to.be.undefined;
expect(() => {
//@ts-expect-error uses private method.
this.realm._objectForObjectKey(AgeSchema.name, "invalid int64_t");
}).throws("Expected value to be a numeric string, got a string");
});

it("modifying object fetched from key propagates", async function (this: Mocha.Context & RealmContext) {
Expand Down
36 changes: 20 additions & 16 deletions integration-tests/tests/src/tests/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const NullableBasicTypesSchema = {
};

describe("Results", () => {
afterEach(() => {
Realm.clearTestState();
});

describe("General functionality", () => {
openRealmBeforeEach({ schema: [TestObject] });

Expand Down Expand Up @@ -169,7 +173,7 @@ describe("Results", () => {

expect(() => {
objects.indexOf(object4);
}).throws("Realm object is from another Realm");
}).throws("Object of type 'TestObject' does not match Results type 'TestObject'");
});

it("should be read-only", function (this: RealmContext) {
Expand All @@ -186,11 +190,11 @@ describe("Results", () => {
expect(() => {
//@ts-expect-error Should be an invalid write to read-only object.
objects[0] = { doubleCol: 0 };
}).throws(select({ reactNative: "Cannot assign to index", default: "Cannot assign to read only index 0" }));
}).throws("Assigning into a Results is not supported");
expect(() => {
//@ts-expect-error Should be an invalid write to read-only object.
objects[1] = { doubleCol: 0 };
}).throws(select({ reactNative: "Cannot assign to index", default: "Cannot assign to read only index 1" }));
}).throws("Assigning into a Results is not supported");
expect(() => {
//@ts-expect-error Should be an invalid write to read-only object.
objects.length = 0;
Expand Down Expand Up @@ -511,11 +515,11 @@ describe("Results", () => {
expect(() => {
//@ts-expect-error Expected to be an invalid sorted argument.
objects.sorted(1);
}).throws("JS value must be of type 'string'");
}).throws("Expected 'argument' to be property name and optional bool or an array of descriptors, got a number");
expect(() => {
//@ts-expect-error Expected to be an invalid sorted argument.
objects.sorted([1]);
}).throws("JS value must be of type 'string'");
}).throws("Expected 'descriptor[0]' to be string or array with two elements [string, boolean], got a number");

expect(() => {
objects.sorted("fish");
Expand All @@ -527,7 +531,7 @@ describe("Results", () => {
expect(() => {
//@ts-expect-error Expected to be an invalid sorted argument.
objects.sorted(["valueCol", "primaryCol"], true);
}).throws("Second argument is not allowed if passed an array of sort descriptors");
}).throws("Expected second 'argument' to be undefined, got a boolean");

realm.close();
});
Expand Down Expand Up @@ -752,28 +756,28 @@ describe("Results", () => {
["boolCol", "stringCol", "dataCol"].forEach((colName) => {
expect(() => {
results.min(colName);
}).throws(`Cannot min property '${colName}'`);
}).throws("Operation 'min' not supported for");
});

// bool, string & data columns don't support 'max'
["boolCol", "stringCol", "dataCol"].forEach((colName) => {
expect(() => {
results.max(colName);
}).throws(`Cannot max property '${colName}'`);
}).throws(`Operation 'max' not supported for`);
});

// bool, string, date & data columns don't support 'avg'
["boolCol", "stringCol", "dateCol", "dataCol"].forEach((colName) => {
expect(() => {
results.avg(colName);
}).throws(`Cannot avg property '${colName}'`);
}).throws(`Operation 'average' not supported for`);
});

// bool, string, date & data columns don't support 'sum'
["boolCol", "stringCol", "dateCol", "dataCol"].forEach((colName) => {
expect(() => {
results.sum(colName);
}).throws(`Cannot sum property '${colName}'`);
}).throws(`Operation 'sum' not supported for`);
});
});

Expand All @@ -784,16 +788,16 @@ describe("Results", () => {
const results = this.realm.objects("NullableBasicTypesObject");
expect(() => {
results.min("foo");
}).throws("Property 'foo' does not exist on object 'NullableBasicTypesObject'");
}).throws("Property 'foo' does not exist on 'NullableBasicTypesObject' objects");
expect(() => {
results.max("foo");
}).throws("Property 'foo' does not exist on object 'NullableBasicTypesObject'");
}).throws("Property 'foo' does not exist on 'NullableBasicTypesObject' objects");
expect(() => {
results.sum("foo");
}).throws("Property 'foo' does not exist on object 'NullableBasicTypesObject'");
}).throws("Property 'foo' does not exist on 'NullableBasicTypesObject' objects");
expect(() => {
results.avg("foo");
}).throws("Property 'foo' does not exist on object 'NullableBasicTypesObject'");
}).throws("Property 'foo' does not exist on 'NullableBasicTypesObject' objects");
});
});

Expand Down Expand Up @@ -979,11 +983,11 @@ describe("Results", () => {
this.realm.write(() => {
results.update("unknownCol", "world");
});
}).throws("No such property: unknownCol");
}).throws("Property 'unknownCol' does not exist on 'NullableBasicTypesObject' objects");

expect(() => {
results.update("stringCol", "world");
}).throws("Can only 'update' objects within a transaction.");
}).throws("Cannot modify managed objects outside of a write transaction.");
});
});
});
8 changes: 4 additions & 4 deletions integration-tests/tests/src/tests/sync/client-reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function waitServerSideClientResetDiscardUnsyncedChangesCallbacks(

await realm.syncSession?.uploadAllLocalChanges();
await triggerClientReset(app, user);
await resetHandle.promise;
await resetHandle;
}

async function waitServerSideClientResetRecoveryCallbacks(
Expand Down Expand Up @@ -139,7 +139,7 @@ async function waitServerSideClientResetRecoveryCallbacks(

await realm.syncSession?.uploadAllLocalChanges();
await triggerClientReset(app, user);
await resetHandle.promise;
await resetHandle;
}

async function waitSimulatedClientResetDiscardUnsyncedChangesCallbacks(
Expand Down Expand Up @@ -189,7 +189,7 @@ async function waitSimulatedClientResetDiscardUnsyncedChangesCallbacks(
// 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
await resetHandle.promise;
await resetHandle;
}

async function waitSimulatedClientResetRecoverCallbacks(
Expand Down Expand Up @@ -243,7 +243,7 @@ async function waitSimulatedClientResetRecoverCallbacks(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore calling undocumented method _simulateError
session._simulateError(211, "Simulate Client Reset", "realm::sync::ProtocolError", false); // 211 -> diverging histories; 217 -> synchronization no longer possible for client-side file
await resetHandle.promise;
await resetHandle;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions integration-tests/tests/src/tests/sync/flexible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
this.timeout(60_000); // TODO: Temporarily hardcoded until envs are set up.
importAppBefore("with-db-flx");
authenticateUserBefore();
afterEach(() => {
Realm.clearTestState();
});

describe("Configuration", () => {
afterEach(() => {
Realm.clearTestState();
});

describe("flexible sync Realm config", function () {
it.skip("respects cancelWaitOnNonFatalError", async function () {
this.timeout(2_000);
Expand Down Expand Up @@ -477,11 +476,11 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
});

await realm.syncSession?.uploadAllLocalChanges();
await callbackHandle.promise;
await callbackHandle;
});
});

describe("With realm opened before", function () {
describe("with realm opened before", function () {
openRealmBeforeEach({
schema: [FlexiblePersonSchema, DogSchema],
sync: {
Expand Down Expand Up @@ -1769,16 +1768,17 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
it("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"));

this.realm.write(() => {
const tom = this.realm.write(() =>
this.realm.create<IPerson>(FlexiblePersonSchema.name, {
_id: new BSON.ObjectId(),
name: "Tom Old",
age: 99,
});
});
}),
);

expect(tom.isValid()).equals(true);
await this.realm.syncSession?.downloadAllServerChanges();
expect(this.realm.objects(FlexiblePersonSchema.name)).to.have.length(0);
expect(tom.isValid()).equals(false);
});

it("throw an exception 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) {
Expand Down
Loading

0 comments on commit 7600aea

Please sign in to comment.