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
committed by GitHub
parent 1e8ba742a8
commit 585938ca2c
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 httpRequestServer = "http://localhost:" + port;
const app = express();
app.use(bodyParser.json({ 'type': '*/*' }));
app.get("/hello", function(req, res){
res.json({response: "OK"});
});
function startServer(done) {
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");
});
app.get("/404", function(req, res){
res.status(404);
res.send("NO");
});
app.get("/301", function(req, res){
res.status(301);
res.location("/hello");
res.send();
});
app.get("/301", function(req, res){
res.status(301);
res.location("/hello");
res.send();
});
app.post('/echo', function(req, res){
res.json(req.body);
});
app.post('/echo', function(req, res){
res.json(req.body);
});
app.get('/qs', function(req, res){
res.json(req.query);
});
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"

View File

@@ -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);
});

View File

@@ -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);

View File

@@ -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';

View File

@@ -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 => {

View File

@@ -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);
};
}
};
@@ -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);
};
}
}

View File

@@ -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

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
// 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

View File

@@ -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>;

View File

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