Even faster tests (#4868)
* Various improvements in test name / de-duplications * Reverts to class by class deletion, introduced fast mode that just delete data for mongo - Speeds up are incredible Executed 1695 of 1713 specs INCOMPLETE (18 PENDING) in 4 mins 19 secs. * Adds documentation about the deleteEverything
This commit is contained in:
@@ -31,6 +31,22 @@ const MongoClient = mongodb.MongoClient;
|
||||
const ReadPreference = mongodb.ReadPreference;
|
||||
|
||||
const MongoSchemaCollectionName = '_SCHEMA';
|
||||
|
||||
const storageAdapterAllCollections = mongoAdapter => {
|
||||
return mongoAdapter.connect()
|
||||
.then(() => mongoAdapter.database.collections())
|
||||
.then(collections => {
|
||||
return collections.filter(collection => {
|
||||
if (collection.namespace.match(/\.system\./)) {
|
||||
return false;
|
||||
}
|
||||
// TODO: If you have one app with a collection prefix that happens to be a prefix of another
|
||||
// apps prefix, this will go very very badly. We should fix that somehow.
|
||||
return (collection.collectionName.indexOf(mongoAdapter._collectionPrefix) == 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const convertParseSchemaToMongoSchema = ({...schema}) => {
|
||||
delete schema.fields._rperm;
|
||||
delete schema.fields._wperm;
|
||||
@@ -297,9 +313,9 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
dropDatabase() {
|
||||
if (!this.database) { return Promise.resolve(); }
|
||||
return this.database.dropDatabase();
|
||||
deleteAllClasses(fast: boolean) {
|
||||
return storageAdapterAllCollections(this)
|
||||
.then(collections => Promise.all(collections.map(collection => fast ? collection.remove({}) : collection.drop())));
|
||||
}
|
||||
|
||||
// Remove the column and all the data. For Relations, the _Join collection is handled
|
||||
|
||||
@@ -959,10 +959,6 @@ 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
|
||||
|
||||
@@ -31,7 +31,7 @@ export interface StorageAdapter {
|
||||
createClass(className: string, schema: SchemaType): Promise<void>;
|
||||
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void>;
|
||||
deleteClass(className: string): Promise<void>;
|
||||
dropDatabase(): Promise<void>;
|
||||
deleteAllClasses(fast: boolean): Promise<void>;
|
||||
deleteFields(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>;
|
||||
getAllClasses(): Promise<StorageClass[]>;
|
||||
getClass(className: string): Promise<StorageClass>;
|
||||
|
||||
@@ -426,7 +426,7 @@ class DatabaseController {
|
||||
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid field name for update: ${fieldName}`);
|
||||
}
|
||||
});
|
||||
for (const updateOperation: any in update) {
|
||||
for (const updateOperation in update) {
|
||||
if (Object.keys(updateOperation).some(innerKey => innerKey.includes('$') || innerKey.includes('.'))) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
|
||||
}
|
||||
@@ -654,11 +654,16 @@ class DatabaseController {
|
||||
}
|
||||
|
||||
// Won't delete collections in the system namespace
|
||||
// Returns a promise.
|
||||
deleteEverything() {
|
||||
/**
|
||||
* Delete all classes and clears the schema cache
|
||||
*
|
||||
* @param {boolean} fast set to true if it's ok to just delete rows and not indexes
|
||||
* @returns {Promise<void>} when the deletions completes
|
||||
*/
|
||||
deleteEverything(fast: boolean = false): Promise<void> {
|
||||
this.schemaPromise = null;
|
||||
return Promise.all([
|
||||
this.adapter.dropDatabase(),
|
||||
this.adapter.deleteAllClasses(fast),
|
||||
this.schemaCache.clear()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import AppCache from './cache';
|
||||
|
||||
//Used by tests
|
||||
export function destroyAllDataPermanently() {
|
||||
/**
|
||||
* Destroys all data in the database
|
||||
* @param {boolean} fast set to true if it's ok to just drop objects and not indexes.
|
||||
*/
|
||||
export function destroyAllDataPermanently(fast) {
|
||||
if (!process.env.TESTING) {
|
||||
throw 'Only supported in test environment';
|
||||
}
|
||||
return Promise.all(Object.keys(AppCache.cache).map(appId => {
|
||||
const app = AppCache.get(appId);
|
||||
if (app.databaseController) {
|
||||
return app.databaseController.deleteEverything();
|
||||
return app.databaseController.deleteEverything(fast);
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user