ci: Fix flaky tests (#8468)
This commit is contained in:
@@ -348,7 +348,7 @@ describe('Auth Adapter features', () => {
|
|||||||
it('should strip out authData if required', async () => {
|
it('should strip out authData if required', async () => {
|
||||||
const spy = spyOn(modernAdapter3, 'validateOptions').and.callThrough();
|
const spy = spyOn(modernAdapter3, 'validateOptions').and.callThrough();
|
||||||
const afterSpy = spyOn(modernAdapter3, 'afterFind').and.callThrough();
|
const afterSpy = spyOn(modernAdapter3, 'afterFind').and.callThrough();
|
||||||
await reconfigureServer({ auth: { modernAdapter3 }, silent: false });
|
await reconfigureServer({ auth: { modernAdapter3 } });
|
||||||
const user = new Parse.User();
|
const user = new Parse.User();
|
||||||
await user.save({ authData: { modernAdapter3: { id: 'modernAdapter3Data' } } });
|
await user.save({ authData: { modernAdapter3: { id: 'modernAdapter3Data' } } });
|
||||||
await user.fetch({ sessionToken: user.getSessionToken() });
|
await user.fetch({ sessionToken: user.getSessionToken() });
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ describe('Idempotency', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
it('should enforce idempotency for cloud code function', async () => {
|
it('should enforce idempotency for cloud code function', async () => {
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {
|
|||||||
});
|
});
|
||||||
it('can connect', async () => {
|
it('can connect', async () => {
|
||||||
await reconfigureServer({
|
await reconfigureServer({
|
||||||
|
appId: 'redis_live_query',
|
||||||
startLiveQueryServer: true,
|
startLiveQueryServer: true,
|
||||||
liveQuery: {
|
liveQuery: {
|
||||||
classNames: ['TestObject'],
|
classNames: ['TestObject'],
|
||||||
@@ -36,6 +37,7 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {
|
|||||||
|
|
||||||
it('can call connect twice', async () => {
|
it('can call connect twice', async () => {
|
||||||
const server = await reconfigureServer({
|
const server = await reconfigureServer({
|
||||||
|
appId: 'redis_live_query',
|
||||||
startLiveQueryServer: true,
|
startLiveQueryServer: true,
|
||||||
liveQuery: {
|
liveQuery: {
|
||||||
classNames: ['TestObject'],
|
classNames: ['TestObject'],
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ describe('ParseLiveQueryServer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe_only_db('mongo')('initialization', () => {
|
describe_only_db('mongo')('initialization', () => {
|
||||||
|
beforeEach(() => reconfigureServer({ appId: 'mongo_init_test' }));
|
||||||
it('can be initialized through ParseServer without liveQueryServerOptions', async () => {
|
it('can be initialized through ParseServer without liveQueryServerOptions', async () => {
|
||||||
const parseServer = await ParseServer.startApp({
|
const parseServer = await ParseServer.startApp({
|
||||||
appId: 'hello',
|
appId: 'hello',
|
||||||
|
|||||||
@@ -198,6 +198,10 @@ beforeAll(async () => {
|
|||||||
Parse.serverURL = 'http://localhost:' + port + '/1';
|
Parse.serverURL = 'http://localhost:' + port + '/1';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(function (done) {
|
afterEach(function (done) {
|
||||||
const afterLogOut = async () => {
|
const afterLogOut = async () => {
|
||||||
if (Object.keys(openConnections).length > 0) {
|
if (Object.keys(openConnections).length > 0) {
|
||||||
@@ -214,6 +218,7 @@ afterEach(function (done) {
|
|||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
Parse.Cloud._removeAllHooks();
|
Parse.Cloud._removeAllHooks();
|
||||||
|
Parse.CoreManager.getLiveQueryController().setDefaultLiveQueryClient();
|
||||||
defaults.protectedFields = { _User: { '*': ['email'] } };
|
defaults.protectedFields = { _User: { '*': ['email'] } };
|
||||||
databaseAdapter
|
databaseAdapter
|
||||||
.getAllClasses()
|
.getAllClasses()
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ describe('server', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can get starting state', async () => {
|
it('can get starting state', async () => {
|
||||||
await reconfigureServer({ appId: 'test2', silent: false });
|
await reconfigureServer({ appId: 'test2' });
|
||||||
const parseServer = new ParseServer.ParseServer({
|
const parseServer = new ParseServer.ParseServer({
|
||||||
...defaultConfiguration,
|
...defaultConfiguration,
|
||||||
appId: 'test2',
|
appId: 'test2',
|
||||||
|
|||||||
@@ -626,6 +626,16 @@ export class Config {
|
|||||||
return new Date(now.getTime() + this.sessionLength * 1000);
|
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() {
|
get invalidLinkURL() {
|
||||||
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
|
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AppCache from './cache';
|
import AppCache from './cache';
|
||||||
|
import SchemaCache from './Adapters/Cache/SchemaCache';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys all data in the database
|
* Destroys all data in the database
|
||||||
@@ -11,11 +12,17 @@ export function destroyAllDataPermanently(fast) {
|
|||||||
return Promise.all(
|
return Promise.all(
|
||||||
Object.keys(AppCache.cache).map(appId => {
|
Object.keys(AppCache.cache).map(appId => {
|
||||||
const app = AppCache.get(appId);
|
const app = AppCache.get(appId);
|
||||||
if (app.databaseController) {
|
const deletePromises = [];
|
||||||
return app.databaseController.deleteEverything(fast);
|
if (app.cacheAdapter) {
|
||||||
} else {
|
deletePromises.push(app.cacheAdapter.clear());
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
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) {
|
if (validationHandler && validationHandler.rateLimit) {
|
||||||
addRateLimit(
|
addRateLimit(
|
||||||
{ requestPath: `/functions/${functionName}`, ...validationHandler.rateLimit },
|
{ requestPath: `/functions/${functionName}`, ...validationHandler.rateLimit },
|
||||||
Parse.applicationId
|
Parse.applicationId,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -191,7 +192,8 @@ ParseCloud.beforeSave = function (parseClass, handler, validationHandler) {
|
|||||||
requestMethods: ['POST', 'PUT'],
|
requestMethods: ['POST', 'PUT'],
|
||||||
...validationHandler.rateLimit,
|
...validationHandler.rateLimit,
|
||||||
},
|
},
|
||||||
Parse.applicationId
|
Parse.applicationId,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -237,7 +239,8 @@ ParseCloud.beforeDelete = function (parseClass, handler, validationHandler) {
|
|||||||
requestMethods: 'DELETE',
|
requestMethods: 'DELETE',
|
||||||
...validationHandler.rateLimit,
|
...validationHandler.rateLimit,
|
||||||
},
|
},
|
||||||
Parse.applicationId
|
Parse.applicationId,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -278,7 +281,8 @@ ParseCloud.beforeLogin = function (handler, validationHandler) {
|
|||||||
if (validationHandler && validationHandler.rateLimit) {
|
if (validationHandler && validationHandler.rateLimit) {
|
||||||
addRateLimit(
|
addRateLimit(
|
||||||
{ requestPath: `/login`, requestMethods: 'POST', ...validationHandler.rateLimit },
|
{ requestPath: `/login`, requestMethods: 'POST', ...validationHandler.rateLimit },
|
||||||
Parse.applicationId
|
Parse.applicationId,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -456,7 +460,8 @@ ParseCloud.beforeFind = function (parseClass, handler, validationHandler) {
|
|||||||
requestMethods: 'GET',
|
requestMethods: 'GET',
|
||||||
...validationHandler.rateLimit,
|
...validationHandler.rateLimit,
|
||||||
},
|
},
|
||||||
Parse.applicationId
|
Parse.applicationId,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -761,6 +766,8 @@ ParseCloud.afterLiveQueryEvent = function (parseClass, handler, validationHandle
|
|||||||
|
|
||||||
ParseCloud._removeAllHooks = () => {
|
ParseCloud._removeAllHooks = () => {
|
||||||
triggers._unregisterAll();
|
triggers._unregisterAll();
|
||||||
|
const config = Config.get(Parse.applicationId);
|
||||||
|
config?.unregisterRateLimiters();
|
||||||
};
|
};
|
||||||
|
|
||||||
ParseCloud.useMasterKey = () => {
|
ParseCloud.useMasterKey = () => {
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ export function promiseEnforceMasterKeyAccess(request) {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addRateLimit = (route, config) => {
|
export const addRateLimit = (route, config, cloud) => {
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
config = Config.get(config);
|
config = Config.get(config);
|
||||||
}
|
}
|
||||||
@@ -545,6 +545,7 @@ export const addRateLimit = (route, config) => {
|
|||||||
},
|
},
|
||||||
store: redisStore.store,
|
store: redisStore.store,
|
||||||
}),
|
}),
|
||||||
|
cloud,
|
||||||
});
|
});
|
||||||
Config.put(config);
|
Config.put(config);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user