Skip to content

Commit 7319aab

Browse files
committed
improves test performance on mongodb (#4862)
* improves test performance on mongodb * Removes unused methdos
1 parent ec27bc7 commit 7319aab

10 files changed

+88
-46
lines changed

spec/HTTPRequest.spec.js

+32-22
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,45 @@ const httpRequest = require("../src/cloud-code/httpRequest"),
88
const port = 13371;
99
const httpRequestServer = "http://localhost:" + port;
1010

11-
const app = express();
12-
app.use(bodyParser.json({ 'type': '*/*' }));
13-
app.get("/hello", function(req, res){
14-
res.json({response: "OK"});
15-
});
16-
17-
app.get("/404", function(req, res){
18-
res.status(404);
19-
res.send("NO");
20-
});
11+
function startServer(done) {
12+
const app = express();
13+
app.use(bodyParser.json({ 'type': '*/*' }));
14+
app.get("/hello", function(req, res){
15+
res.json({response: "OK"});
16+
});
2117

22-
app.get("/301", function(req, res){
23-
res.status(301);
24-
res.location("/hello");
25-
res.send();
26-
});
18+
app.get("/404", function(req, res){
19+
res.status(404);
20+
res.send("NO");
21+
});
2722

28-
app.post('/echo', function(req, res){
29-
res.json(req.body);
30-
});
23+
app.get("/301", function(req, res){
24+
res.status(301);
25+
res.location("/hello");
26+
res.send();
27+
});
3128

32-
app.get('/qs', function(req, res){
33-
res.json(req.query);
34-
});
29+
app.post('/echo', function(req, res){
30+
res.json(req.body);
31+
});
3532

36-
app.listen(13371);
33+
app.get('/qs', function(req, res){
34+
res.json(req.query);
35+
});
3736

37+
return app.listen(13371, undefined, done);
38+
}
3839

3940
describe("httpRequest", () => {
41+
let server;
42+
beforeAll((done) => {
43+
server = startServer(done);
44+
});
45+
46+
afterAll((done) => {
47+
server.close(done);
48+
});
49+
4050
it("should do /hello", (done) => {
4151
httpRequest({
4252
url: httpRequestServer + "/hello"

spec/MongoStorageAdapter.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const databaseURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDataba
99
describe_only_db('mongo')('MongoStorageAdapter', () => {
1010
beforeEach(done => {
1111
new MongoStorageAdapter({ uri: databaseURI })
12-
.deleteAllClasses()
12+
.dropDatabase()
1313
.then(done, fail);
1414
});
1515

spec/ParseHooks.spec.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ const port = 12345;
1010
const hookServerURL = "http://localhost:" + port;
1111
const AppCache = require('../src/cache').AppCache;
1212

13-
const app = express();
14-
app.use(bodyParser.json({ 'type': '*/*' }))
15-
app.listen(12345);
16-
1713
describe('Hooks', () => {
14+
let server;
15+
let app;
16+
beforeAll((done) => {
17+
app = express();
18+
app.use(bodyParser.json({ 'type': '*/*' }))
19+
server = app.listen(12345, undefined, done);
20+
});
21+
22+
afterAll((done) => {
23+
server.close(done);
24+
});
25+
1826
it("should have no hooks registered", (done) => {
1927
Parse.Hooks.getFunctions().then((res) => {
2028
expect(res.constructor).toBe(Array.prototype.constructor);

spec/ParseServer.spec.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ import ParseServer from '../src/ParseServer';
77

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

10-
const app = express();
11-
app.get('/health', function(req, res){
12-
res.json({
13-
status: 'ok'
10+
let server;
11+
beforeAll((done) => {
12+
const app = express();
13+
app.get('/health', function(req, res){
14+
res.json({
15+
status: 'ok'
16+
});
1417
});
18+
server = app.listen(13376, undefined, done);
19+
});
20+
21+
afterAll((done) => {
22+
server.close(done);
1523
});
16-
app.listen(13376);
1724

1825
it('validate good server url', (done) => {
1926
Parse.serverURL = 'http://localhost:13376';

spec/PostgresStorageAdapter.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const dropTable = (client, className) => {
1212
describe_only_db('postgres')('PostgresStorageAdapter', () => {
1313
const adapter = new PostgresStorageAdapter({ uri: databaseURI })
1414
beforeEach(() => {
15-
return adapter.deleteAllClasses();
15+
return adapter.dropDatabase();
1616
});
1717

1818
it('schemaUpgrade, upgrade the database schema when schema changes', done => {

spec/helper.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,25 @@ global.jfail = function(err) {
411411

412412
global.it_exclude_dbs = excluded => {
413413
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
414-
return xit;
414+
return (name, suite) => {
415+
return xit(`[${excluded}] ${name}`, suite);
416+
};
415417
} else {
416-
return it;
418+
return (name, suite) => {
419+
return it(`[${excluded}] ${name}`, suite);
420+
};
417421
}
418422
}
419423

420424
global.it_only_db = db => {
421425
if (process.env.PARSE_SERVER_TEST_DB === db) {
422-
return it;
426+
return (name, suite) => {
427+
return it(`[${db}] ${name}`, suite);
428+
};
423429
} else {
424-
return xit;
430+
return (name, suite) => {
431+
return xit(`[${db}] ${name}`, suite);
432+
};
425433
}
426434
};
427435

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

436444
global.describe_only_db = db => {
437445
if (process.env.PARSE_SERVER_TEST_DB == db) {
438-
return describe;
446+
return (name, suite) => {
447+
return describe(`[${db}] ${name}`, suite);
448+
};
439449
} else if (!process.env.PARSE_SERVER_TEST_DB && db == 'mongo') {
440-
return describe;
450+
return (name, suite) => {
451+
return describe(`[${db}] ${name}`, suite);
452+
};
441453
} else {
442-
return () => {};
454+
return (name, suite) => {
455+
return xdescribe(`[${db}] ${name}`, suite);
456+
};
443457
}
444458
}
445459

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ export class MongoStorageAdapter implements StorageAdapter {
313313
.catch(err => this.handleError(err));
314314
}
315315

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

323321
// Remove the column and all the data. For Relations, the _Join collection is handled

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+4
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
959959
});
960960
}
961961

962+
dropDatabase() {
963+
return this.deleteAllClasses();
964+
}
965+
962966
// Remove the column and all the data. For Relations, the _Join collection is handled
963967
// specially, this function does not delete _Join columns. It should, however, indicate
964968
// that the relation fields does not exist anymore. In mongo, this means removing it from

src/Adapters/Storage/StorageAdapter.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface StorageAdapter {
3232
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void>;
3333
deleteClass(className: string): Promise<void>;
3434
deleteAllClasses(): Promise<void>;
35+
dropDatabase(): Promise<void>;
3536
deleteFields(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>;
3637
getAllClasses(): Promise<StorageClass[]>;
3738
getClass(className: string): Promise<StorageClass>;

src/Controllers/DatabaseController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class DatabaseController {
658658
deleteEverything() {
659659
this.schemaPromise = null;
660660
return Promise.all([
661-
this.adapter.deleteAllClasses(),
661+
this.adapter.dropDatabase(),
662662
this.schemaCache.clear()
663663
]);
664664
}

0 commit comments

Comments
 (0)