ci: Fix flaky tests (#8468)
This commit is contained in:
@@ -626,6 +626,16 @@ export class Config {
|
||||
return new Date(now.getTime() + this.sessionLength * 1000);
|
||||
}
|
||||
|
||||
unregisterRateLimiters() {
|
||||
let i = this.rateLimits?.length;
|
||||
while (i--) {
|
||||
const limit = this.rateLimits[i];
|
||||
if (limit.cloud) {
|
||||
this.rateLimits.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get invalidLinkURL() {
|
||||
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import AppCache from './cache';
|
||||
import SchemaCache from './Adapters/Cache/SchemaCache';
|
||||
|
||||
/**
|
||||
* Destroys all data in the database
|
||||
@@ -11,11 +12,17 @@ export function destroyAllDataPermanently(fast) {
|
||||
return Promise.all(
|
||||
Object.keys(AppCache.cache).map(appId => {
|
||||
const app = AppCache.get(appId);
|
||||
if (app.databaseController) {
|
||||
return app.databaseController.deleteEverything(fast);
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
const deletePromises = [];
|
||||
if (app.cacheAdapter) {
|
||||
deletePromises.push(app.cacheAdapter.clear());
|
||||
}
|
||||
if (app.databaseController) {
|
||||
deletePromises.push(app.databaseController.deleteEverything(fast));
|
||||
} else if (app.databaseAdapter) {
|
||||
SchemaCache.clear();
|
||||
deletePromises.push(app.databaseAdapter.deleteAllClasses(fast));
|
||||
}
|
||||
return Promise.all(deletePromises);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,7 +128,8 @@ ParseCloud.define = function (functionName, handler, validationHandler) {
|
||||
if (validationHandler && validationHandler.rateLimit) {
|
||||
addRateLimit(
|
||||
{ requestPath: `/functions/${functionName}`, ...validationHandler.rateLimit },
|
||||
Parse.applicationId
|
||||
Parse.applicationId,
|
||||
true
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -191,7 +192,8 @@ ParseCloud.beforeSave = function (parseClass, handler, validationHandler) {
|
||||
requestMethods: ['POST', 'PUT'],
|
||||
...validationHandler.rateLimit,
|
||||
},
|
||||
Parse.applicationId
|
||||
Parse.applicationId,
|
||||
true
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -237,7 +239,8 @@ ParseCloud.beforeDelete = function (parseClass, handler, validationHandler) {
|
||||
requestMethods: 'DELETE',
|
||||
...validationHandler.rateLimit,
|
||||
},
|
||||
Parse.applicationId
|
||||
Parse.applicationId,
|
||||
true
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -278,7 +281,8 @@ ParseCloud.beforeLogin = function (handler, validationHandler) {
|
||||
if (validationHandler && validationHandler.rateLimit) {
|
||||
addRateLimit(
|
||||
{ requestPath: `/login`, requestMethods: 'POST', ...validationHandler.rateLimit },
|
||||
Parse.applicationId
|
||||
Parse.applicationId,
|
||||
true
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -456,7 +460,8 @@ ParseCloud.beforeFind = function (parseClass, handler, validationHandler) {
|
||||
requestMethods: 'GET',
|
||||
...validationHandler.rateLimit,
|
||||
},
|
||||
Parse.applicationId
|
||||
Parse.applicationId,
|
||||
true
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -761,6 +766,8 @@ ParseCloud.afterLiveQueryEvent = function (parseClass, handler, validationHandle
|
||||
|
||||
ParseCloud._removeAllHooks = () => {
|
||||
triggers._unregisterAll();
|
||||
const config = Config.get(Parse.applicationId);
|
||||
config?.unregisterRateLimiters();
|
||||
};
|
||||
|
||||
ParseCloud.useMasterKey = () => {
|
||||
|
||||
@@ -466,7 +466,7 @@ export function promiseEnforceMasterKeyAccess(request) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
export const addRateLimit = (route, config) => {
|
||||
export const addRateLimit = (route, config, cloud) => {
|
||||
if (typeof config === 'string') {
|
||||
config = Config.get(config);
|
||||
}
|
||||
@@ -545,6 +545,7 @@ export const addRateLimit = (route, config) => {
|
||||
},
|
||||
store: redisStore.store,
|
||||
}),
|
||||
cloud,
|
||||
});
|
||||
Config.put(config);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user