Skip to content

Postgres: Properly initialize database on startup and debugger #7255

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

Merged
merged 6 commits into from
Mar 10, 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
87 changes: 71 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"mongodb": "3.6.3",
"mustache": "4.1.0",
"parse": "3.1.0",
"pg-monitor": "1.4.1",
"pg-promise": "10.9.2",
"pluralize": "8.0.0",
"redis": "3.0.2",
Expand Down
6 changes: 3 additions & 3 deletions spec/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ describe('Auth', () => {
const role2 = new Parse.Role('role2loadtest' + i, acl2);
role.getUsers().add([user]);
role2.getUsers().add([user2]);
roles.push(role.save());
roles.push(role2.save());
roles.push(role);
roles.push(role2);
}
const savedRoles = await Promise.all(roles);
const savedRoles = await Parse.Object.saveAll(roles);
expect(savedRoles.length).toBe(rolesNumber * 2);
const cloudRoles = await userAuth.getRolesForUser();
const cloudRoles2 = await user2Auth.getRolesForUser();
Expand Down
2 changes: 2 additions & 0 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ describe('miscellaneous', function () {
const config = Config.get('test');
// Remove existing data to clear out unique index
TestUtils.destroyAllDataPermanently()
.then(() => config.database.adapter.performInitialization({ VolatileClassesSchemas: [] }))
.then(() => config.database.adapter.createClass('_User', userSchema))
.then(() =>
config.database.adapter
Expand Down Expand Up @@ -210,6 +211,7 @@ describe('miscellaneous', function () {
const config = Config.get('test');
// Remove existing data to clear out unique index
TestUtils.destroyAllDataPermanently()
.then(() => config.database.adapter.performInitialization({ VolatileClassesSchemas: [] }))
.then(() => config.database.adapter.createClass('_User', userSchema))
.then(() =>
config.database.adapter.createObject('_User', userSchema, {
Expand Down
2 changes: 0 additions & 2 deletions spec/ParseGraphQLSchema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ describe('ParseGraphQLSchema', () => {
const graphQLSchema = await parseGraphQLSchema.load();
const updatedGraphQLSchema = await parseGraphQLSchema.load();
expect(graphQLSchema).toBe(updatedGraphQLSchema);
await new Promise(resolve => setTimeout(resolve, 200));
expect(graphQLSchema).toBe(await parseGraphQLSchema.load());
});

it('should load a brand new GraphQL Schema if Parse Schema changes', async () => {
Expand Down
34 changes: 14 additions & 20 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,32 +275,26 @@ describe('Parse.Query testing', () => {
});
});

it('query with limit equal to maxlimit', function (done) {
it('query with limit equal to maxlimit', async () => {
const baz = new TestObject({ foo: 'baz' });
const qux = new TestObject({ foo: 'qux' });
reconfigureServer({ maxLimit: 1 });
Parse.Object.saveAll([baz, qux]).then(function () {
const query = new Parse.Query(TestObject);
query.limit(1);
query.find().then(function (results) {
equal(results.length, 1);
done();
});
});
await reconfigureServer({ maxLimit: 1 });
await Parse.Object.saveAll([baz, qux]);
const query = new Parse.Query(TestObject);
query.limit(1);
const results = await query.find();
equal(results.length, 1);
});

it('query with limit exceeding maxlimit', function (done) {
it('query with limit exceeding maxlimit', async () => {
const baz = new TestObject({ foo: 'baz' });
const qux = new TestObject({ foo: 'qux' });
reconfigureServer({ maxLimit: 1 });
Parse.Object.saveAll([baz, qux]).then(function () {
const query = new Parse.Query(TestObject);
query.limit(2);
query.find().then(function (results) {
equal(results.length, 1);
done();
});
});
await reconfigureServer({ maxLimit: 1 });
await Parse.Object.saveAll([baz, qux]);
const query = new Parse.Query(TestObject);
query.limit(2);
const results = await query.find();
equal(results.length, 1);
});

it('containedIn object array queries', function (done) {
Expand Down
5 changes: 0 additions & 5 deletions spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const ParseServerRESTController = require('../lib/ParseServerRESTController')
.ParseServerRESTController;
const ParseServer = require('../lib/ParseServer').default;
const Parse = require('parse/node').Parse;
const TestUtils = require('../lib/TestUtils');
const semver = require('semver');

let RESTController;
Expand Down Expand Up @@ -183,10 +182,6 @@ describe('ParseServerRESTController', () => {
}
});

beforeEach(async () => {
await TestUtils.destroyAllDataPermanently(true);
});

it('should handle a batch request with transaction = true', done => {
const myObject = new Parse.Object('MyObject'); // This is important because transaction only works on pre-existing collections
myObject
Expand Down
5 changes: 3 additions & 2 deletions spec/PostgresStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ const dropTable = (client, className) => {

describe_only_db('postgres')('PostgresStorageAdapter', () => {
let adapter;
beforeEach(() => {
beforeEach(async () => {
const config = Config.get('test');
adapter = config.database.adapter;
return adapter.deleteAllClasses();
await adapter.deleteAllClasses();
await adapter.performInitialization({ VolatileClassesSchemas: [] });
});

it('schemaUpgrade, upgrade the database schema when schema changes', done => {
Expand Down
1 change: 1 addition & 0 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('SchemaController', () => {
afterEach(async () => {
await config.database.schemaCache.clear();
await TestUtils.destroyAllDataPermanently(false);
await config.database.adapter.performInitialization({ VolatileClassesSchemas: [] });
});

it('can validate one object', done => {
Expand Down
5 changes: 0 additions & 5 deletions spec/batch.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const batch = require('../lib/batch');
const request = require('../lib/request');
const TestUtils = require('../lib/TestUtils');
const semver = require('semver');

const originalURL = '/parse/batch';
Expand Down Expand Up @@ -187,10 +186,6 @@ describe('batch', () => {
}
});

beforeEach(async () => {
await TestUtils.destroyAllDataPermanently(true);
});

it('should handle a batch request with transaction = true', done => {
const myObject = new Parse.Object('MyObject'); // This is important because transaction only works on pre-existing collections
myObject
Expand Down
23 changes: 5 additions & 18 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,18 @@ const reconfigureServer = changedConfiguration => {
const Parse = require('parse/node');
Parse.serverURL = 'http://localhost:' + port + '/1';

beforeEach(done => {
beforeEach(async () => {
try {
Parse.User.enableUnsafeCurrentUser();
} catch (error) {
if (error !== 'You need to call Parse.initialize before using Parse.') {
throw error;
}
}
TestUtils.destroyAllDataPermanently(true)
.catch(error => {
// For tests that connect to their own mongo, there won't be any data to delete.
if (error.message === 'ns not found' || error.message.startsWith('connect ECONNREFUSED')) {
return;
} else {
fail(error);
return;
}
})
.then(reconfigureServer)
.then(() => {
Parse.initialize('test', 'test', 'test');
Parse.serverURL = 'http://localhost:' + port + '/1';
done();
})
.catch(done.fail);
await reconfigureServer();

Parse.initialize('test', 'test', 'test');
Parse.serverURL = 'http://localhost:' + port + '/1';
});

afterEach(function (done) {
Expand Down
7 changes: 6 additions & 1 deletion spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ describe('schemas', () => {
afterEach(async () => {
await config.database.schemaCache.clear();
await TestUtils.destroyAllDataPermanently(false);
await config.database.adapter.performInitialization({ VolatileClassesSchemas: [] });
});

it('requires the master key to get all schemas', done => {
Expand Down Expand Up @@ -2816,7 +2817,11 @@ describe('schemas', () => {
});

describe('index management', () => {
beforeEach(() => require('../lib/TestUtils').destroyAllDataPermanently());
beforeEach(async () => {
await TestUtils.destroyAllDataPermanently(false);
await config.database.adapter.performInitialization({ VolatileClassesSchemas: [] });
});

it('cannot create index if field does not exist', done => {
request({
url: 'http://localhost:8378/1/schemas/NewClass',
Expand Down
Loading