improves test performance on mongodb (#4862)

* improves test performance on mongodb

* Removes unused methdos
This commit is contained in:
Florent Vilmart
2018-06-29 17:09:51 -04:00
parent ec27bc7e8e
commit 7319aabf7a
10 changed files with 88 additions and 46 deletions

View File

@@ -8,35 +8,45 @@ const httpRequest = require("../src/cloud-code/httpRequest"),
const port = 13371; const port = 13371;
const httpRequestServer = "http://localhost:" + port; const httpRequestServer = "http://localhost:" + port;
const app = express(); function startServer(done) {
app.use(bodyParser.json({ 'type': '*/*' })); const app = express();
app.get("/hello", function(req, res){ app.use(bodyParser.json({ 'type': '*/*' }));
res.json({response: "OK"}); app.get("/hello", function(req, res){
}); res.json({response: "OK"});
});
app.get("/404", function(req, res){ app.get("/404", function(req, res){
res.status(404); res.status(404);
res.send("NO"); res.send("NO");
}); });
app.get("/301", function(req, res){ app.get("/301", function(req, res){
res.status(301); res.status(301);
res.location("/hello"); res.location("/hello");
res.send(); res.send();
}); });
app.post('/echo', function(req, res){ app.post('/echo', function(req, res){
res.json(req.body); res.json(req.body);
}); });
app.get('/qs', function(req, res){ app.get('/qs', function(req, res){
res.json(req.query); res.json(req.query);
}); });
app.listen(13371);
return app.listen(13371, undefined, done);
}
describe("httpRequest", () => { describe("httpRequest", () => {
let server;
beforeAll((done) => {
server = startServer(done);
});
afterAll((done) => {
server.close(done);
});
it("should do /hello", (done) => { it("should do /hello", (done) => {
httpRequest({ httpRequest({
url: httpRequestServer + "/hello" url: httpRequestServer + "/hello"

View File

@@ -9,7 +9,7 @@ const databaseURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDataba
describe_only_db('mongo')('MongoStorageAdapter', () => { describe_only_db('mongo')('MongoStorageAdapter', () => {
beforeEach(done => { beforeEach(done => {
new MongoStorageAdapter({ uri: databaseURI }) new MongoStorageAdapter({ uri: databaseURI })
.deleteAllClasses() .dropDatabase()
.then(done, fail); .then(done, fail);
}); });

View File

@@ -10,11 +10,19 @@ const port = 12345;
const hookServerURL = "http://localhost:" + port; const hookServerURL = "http://localhost:" + port;
const AppCache = require('../src/cache').AppCache; const AppCache = require('../src/cache').AppCache;
const app = express();
app.use(bodyParser.json({ 'type': '*/*' }))
app.listen(12345);
describe('Hooks', () => { 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) => { it("should have no hooks registered", (done) => {
Parse.Hooks.getFunctions().then((res) => { Parse.Hooks.getFunctions().then((res) => {
expect(res.constructor).toBe(Array.prototype.constructor); expect(res.constructor).toBe(Array.prototype.constructor);

View File

@@ -7,13 +7,20 @@ import ParseServer from '../src/ParseServer';
describe('Server Url Checks', () => { describe('Server Url Checks', () => {
const app = express(); let server;
app.get('/health', function(req, res){ beforeAll((done) => {
res.json({ const app = express();
status: 'ok' 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) => { it('validate good server url', (done) => {
Parse.serverURL = 'http://localhost:13376'; Parse.serverURL = 'http://localhost:13376';

View File

@@ -12,7 +12,7 @@ const dropTable = (client, className) => {
describe_only_db('postgres')('PostgresStorageAdapter', () => { describe_only_db('postgres')('PostgresStorageAdapter', () => {
const adapter = new PostgresStorageAdapter({ uri: databaseURI }) const adapter = new PostgresStorageAdapter({ uri: databaseURI })
beforeEach(() => { beforeEach(() => {
return adapter.deleteAllClasses(); return adapter.dropDatabase();
}); });
it('schemaUpgrade, upgrade the database schema when schema changes', done => { it('schemaUpgrade, upgrade the database schema when schema changes', done => {

View File

@@ -411,17 +411,25 @@ global.jfail = function(err) {
global.it_exclude_dbs = excluded => { global.it_exclude_dbs = excluded => {
if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) { if (excluded.indexOf(process.env.PARSE_SERVER_TEST_DB) >= 0) {
return xit; return (name, suite) => {
return xit(`[${excluded}] ${name}`, suite);
};
} else { } else {
return it; return (name, suite) => {
return it(`[${excluded}] ${name}`, suite);
};
} }
} }
global.it_only_db = db => { global.it_only_db = db => {
if (process.env.PARSE_SERVER_TEST_DB === db) { if (process.env.PARSE_SERVER_TEST_DB === db) {
return it; return (name, suite) => {
return it(`[${db}] ${name}`, suite);
};
} else { } else {
return xit; return (name, suite) => {
return xit(`[${db}] ${name}`, suite);
};
} }
}; };
@@ -435,11 +443,17 @@ global.fit_exclude_dbs = excluded => {
global.describe_only_db = db => { global.describe_only_db = db => {
if (process.env.PARSE_SERVER_TEST_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') { } else if (!process.env.PARSE_SERVER_TEST_DB && db == 'mongo') {
return describe; return (name, suite) => {
return describe(`[${db}] ${name}`, suite);
};
} else { } else {
return () => {}; return (name, suite) => {
return xdescribe(`[${db}] ${name}`, suite);
};
} }
} }

View File

@@ -313,11 +313,9 @@ export class MongoStorageAdapter implements StorageAdapter {
.catch(err => this.handleError(err)); .catch(err => this.handleError(err));
} }
// Delete all data known to this adapter. Used for testing. dropDatabase() {
deleteAllClasses() { if (!this.database) { return Promise.resolve(); }
return storageAdapterAllCollections(this) return this.database.dropDatabase();
.then(collections => Promise.all(collections.map(collection => collection.drop())))
.catch(err => this.handleError(err));
} }
// Remove the column and all the data. For Relations, the _Join collection is handled // Remove the column and all the data. For Relations, the _Join collection is handled

View File

@@ -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 // 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 // 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 // that the relation fields does not exist anymore. In mongo, this means removing it from

View File

@@ -32,6 +32,7 @@ export interface StorageAdapter {
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void>; addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void>;
deleteClass(className: string): Promise<void>; deleteClass(className: string): Promise<void>;
deleteAllClasses(): Promise<void>; deleteAllClasses(): Promise<void>;
dropDatabase(): Promise<void>;
deleteFields(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>; deleteFields(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>;
getAllClasses(): Promise<StorageClass[]>; getAllClasses(): Promise<StorageClass[]>;
getClass(className: string): Promise<StorageClass>; getClass(className: string): Promise<StorageClass>;

View File

@@ -658,7 +658,7 @@ class DatabaseController {
deleteEverything() { deleteEverything() {
this.schemaPromise = null; this.schemaPromise = null;
return Promise.all([ return Promise.all([
this.adapter.deleteAllClasses(), this.adapter.dropDatabase(),
this.schemaCache.clear() this.schemaCache.clear()
]); ]);
} }