Skip to content

improves test performance on mongodb #4862

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 2 commits into from
Jun 29, 2018
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
54 changes: 32 additions & 22 deletions spec/HTTPRequest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,45 @@ const httpRequest = require("../src/cloud-code/httpRequest"),
const port = 13371;
const httpRequestServer = "http://localhost:" + port;

const app = express();
app.use(bodyParser.json({ 'type': '*/*' }));
app.get("/hello", function(req, res){
res.json({response: "OK"});
});

app.get("/404", function(req, res){
res.status(404);
res.send("NO");
});
function startServer(done) {
const app = express();
app.use(bodyParser.json({ 'type': '*/*' }));
app.get("/hello", function(req, res){
res.json({response: "OK"});
});

app.get("/301", function(req, res){
res.status(301);
res.location("/hello");
res.send();
});
app.get("/404", function(req, res){
res.status(404);
res.send("NO");
});

app.post('/echo', function(req, res){
res.json(req.body);
});
app.get("/301", function(req, res){
res.status(301);
res.location("/hello");
res.send();
});

app.get('/qs', function(req, res){
res.json(req.query);
});
app.post('/echo', function(req, res){
res.json(req.body);
});

app.listen(13371);
app.get('/qs', function(req, res){
res.json(req.query);
});

return app.listen(13371, undefined, done);
}

describe("httpRequest", () => {
let server;
beforeAll((done) => {
server = startServer(done);
});

afterAll((done) => {
server.close(done);
});

it("should do /hello", (done) => {
httpRequest({
url: httpRequestServer + "/hello"
Expand Down
2 changes: 1 addition & 1 deletion spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const databaseURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDataba
describe_only_db('mongo')('MongoStorageAdapter', () => {
beforeEach(done => {
new MongoStorageAdapter({ uri: databaseURI })
.deleteAllClasses()
.dropDatabase()
.then(done, fail);
});

Expand Down
16 changes: 12 additions & 4 deletions spec/ParseHooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ const port = 12345;
const hookServerURL = "http://localhost:" + port;
const AppCache = require('../src/cache').AppCache;

const app = express();
app.use(bodyParser.json({ 'type': '*/*' }))
app.listen(12345);

describe('Hooks', () => {
let server;
let app;
beforeAll((done) => {
app = express();
app.use(bodyParser.json({ 'type': '*/*' }))
server = app.listen(12345, undefined, done);
});

afterAll((done) => {
server.close(done);
});

it("should have no hooks registered", (done) => {
Parse.Hooks.getFunctions().then((res) => {
expect(res.constructor).toBe(Array.prototype.constructor);
Expand Down
17 changes: 12 additions & 5 deletions spec/ParseServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import ParseServer from '../src/ParseServer';

describe('Server Url Checks', () => {

const app = express();
app.get('/health', function(req, res){
res.json({
status: 'ok'
let server;
beforeAll((done) => {
const app = express();
app.get('/health', function(req, res){
res.json({
status: 'ok'
});
});
server = app.listen(13376, undefined, done);
});

afterAll((done) => {
server.close(done);
});
app.listen(13376);

it('validate good server url', (done) => {
Parse.serverURL = 'http://localhost:13376';
Expand Down
2 changes: 1 addition & 1 deletion spec/PostgresStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const dropTable = (client, className) => {
describe_only_db('postgres')('PostgresStorageAdapter', () => {
const adapter = new PostgresStorageAdapter({ uri: databaseURI })
beforeEach(() => {
return adapter.deleteAllClasses();
return adapter.dropDatabase();
});

it('schemaUpgrade, upgrade the database schema when schema changes', done => {
Expand Down
28 changes: 21 additions & 7 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,25 @@ global.jfail = function(err) {

global.it_exclude_dbs = excluded => {
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
return xit;
return (name, suite) => {
return xit(`[${excluded}] ${name}`, suite);
};
} else {
return it;
return (name, suite) => {
return it(`[${excluded}] ${name}`, suite);
};
}
}

global.it_only_db = db => {
if (process.env.PARSE_SERVER_TEST_DB === db) {
return it;
return (name, suite) => {
return it(`[${db}] ${name}`, suite);
};
} else {
return xit;
return (name, suite) => {
return xit(`[${db}] ${name}`, suite);
};
}
};

Expand All @@ -435,11 +443,17 @@ global.fit_exclude_dbs = excluded => {

global.describe_only_db = db => {
if (process.env.PARSE_SERVER_TEST_DB == db) {
return describe;
return (name, suite) => {
return describe(`[${db}] ${name}`, suite);
};
} else if (!process.env.PARSE_SERVER_TEST_DB && db == 'mongo') {
return describe;
return (name, suite) => {
return describe(`[${db}] ${name}`, suite);
};
} else {
return () => {};
return (name, suite) => {
return xdescribe(`[${db}] ${name}`, suite);
};
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,9 @@ export class MongoStorageAdapter implements StorageAdapter {
.catch(err => this.handleError(err));
}

// Delete all data known to this adapter. Used for testing.
deleteAllClasses() {
return storageAdapterAllCollections(this)
.then(collections => Promise.all(collections.map(collection => collection.drop())))
.catch(err => this.handleError(err));
dropDatabase() {
if (!this.database) { return Promise.resolve(); }
return this.database.dropDatabase();
}

// Remove the column and all the data. For Relations, the _Join collection is handled
Expand Down
4 changes: 4 additions & 0 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
});
}

dropDatabase() {
return this.deleteAllClasses();
}

// Remove the column and all the data. For Relations, the _Join collection is handled
// specially, this function does not delete _Join columns. It should, however, indicate
// that the relation fields does not exist anymore. In mongo, this means removing it from
Expand Down
1 change: 1 addition & 0 deletions src/Adapters/Storage/StorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface StorageAdapter {
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void>;
deleteClass(className: string): Promise<void>;
deleteAllClasses(): Promise<void>;
dropDatabase(): Promise<void>;
deleteFields(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>;
getAllClasses(): Promise<StorageClass[]>;
getClass(className: string): Promise<StorageClass>;
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ class DatabaseController {
deleteEverything() {
this.schemaPromise = null;
return Promise.all([
this.adapter.deleteAllClasses(),
this.adapter.dropDatabase(),
this.schemaCache.clear()
]);
}
Expand Down