Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Fix flaky tests #8468

Merged
merged 23 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/AuthenticationAdaptersV2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('Auth Adapter features', () => {
it('should strip out authData if required', async () => {
const spy = spyOn(modernAdapter3, 'validateOptions').and.callThrough();
const afterSpy = spyOn(modernAdapter3, 'afterFind').and.callThrough();
await reconfigureServer({ auth: { modernAdapter3 }, silent: false });
await reconfigureServer({ auth: { modernAdapter3 } });
const user = new Parse.User();
await user.save({ authData: { modernAdapter3: { id: 'modernAdapter3Data' } } });
await user.fetch({ sessionToken: user.getSessionToken() });
Expand Down
4 changes: 0 additions & 4 deletions spec/Idempotency.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ describe('Idempotency', () => {
});
});

afterAll(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
});

// Tests
it('should enforce idempotency for cloud code function', async () => {
let counter = 0;
Expand Down
2 changes: 2 additions & 0 deletions spec/ParseLiveQueryRedis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {
});
it('can connect', async () => {
await reconfigureServer({
appId: 'redis_live_query',
startLiveQueryServer: true,
liveQuery: {
classNames: ['TestObject'],
Expand Down Expand Up @@ -36,6 +37,7 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {

it('can call connect twice', async () => {
const server = await reconfigureServer({
appId: 'redis_live_query',
startLiveQueryServer: true,
liveQuery: {
classNames: ['TestObject'],
Expand Down
1 change: 1 addition & 0 deletions spec/ParseLiveQueryServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe('ParseLiveQueryServer', function () {
});

describe_only_db('mongo')('initialization', () => {
beforeEach(() => reconfigureServer({ appId: 'mongo_init_test' }));
it('can be initialized through ParseServer without liveQueryServerOptions', async () => {
const parseServer = await ParseServer.startApp({
appId: 'hello',
Expand Down
5 changes: 5 additions & 0 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ beforeAll(async () => {
Parse.serverURL = 'http://localhost:' + port + '/1';
});

beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
});

afterEach(function (done) {
const afterLogOut = async () => {
if (Object.keys(openConnections).length > 0) {
Expand All @@ -214,6 +218,7 @@ afterEach(function (done) {
done();
};
Parse.Cloud._removeAllHooks();
Parse.CoreManager.getLiveQueryController().setDefaultLiveQueryClient();
defaults.protectedFields = { _User: { '*': ['email'] } };
databaseAdapter
.getAllClasses()
Expand Down
2 changes: 1 addition & 1 deletion spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ describe('server', () => {
});

it('can get starting state', async () => {
await reconfigureServer({ appId: 'test2', silent: false });
await reconfigureServer({ appId: 'test2' });
const parseServer = new ParseServer.ParseServer({
...defaultConfiguration,
appId: 'test2',
Expand Down
10 changes: 10 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
Expand Down
13 changes: 10 additions & 3 deletions src/TestUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppCache from './cache';
import SchemaCache from './Adapters/Cache/SchemaCache';

/**
* Destroys all data in the database
Expand All @@ -11,11 +12,17 @@ export function destroyAllDataPermanently(fast) {
return Promise.all(
Object.keys(AppCache.cache).map(appId => {
const app = AppCache.get(appId);
const deletePromises = [];
if (app.cacheAdapter) {
deletePromises.push(app.cacheAdapter.clear());
}
if (app.databaseController) {
return app.databaseController.deleteEverything(fast);
} else {
return Promise.resolve();
deletePromises.push(app.databaseController.deleteEverything(fast));
} else if (app.databaseAdapter) {
SchemaCache.clear();
deletePromises.push(app.databaseAdapter.deleteAllClasses(fast));
}
return Promise.all(deletePromises);
})
);
}
17 changes: 12 additions & 5 deletions src/cloud-code/Parse.Cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
};
Expand Down Expand Up @@ -191,7 +192,8 @@ ParseCloud.beforeSave = function (parseClass, handler, validationHandler) {
requestMethods: ['POST', 'PUT'],
...validationHandler.rateLimit,
},
Parse.applicationId
Parse.applicationId,
true
);
}
};
Expand Down Expand Up @@ -237,7 +239,8 @@ ParseCloud.beforeDelete = function (parseClass, handler, validationHandler) {
requestMethods: 'DELETE',
...validationHandler.rateLimit,
},
Parse.applicationId
Parse.applicationId,
true
);
}
};
Expand Down Expand Up @@ -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
);
}
};
Expand Down Expand Up @@ -456,7 +460,8 @@ ParseCloud.beforeFind = function (parseClass, handler, validationHandler) {
requestMethods: 'GET',
...validationHandler.rateLimit,
},
Parse.applicationId
Parse.applicationId,
true
);
}
};
Expand Down Expand Up @@ -761,6 +766,8 @@ ParseCloud.afterLiveQueryEvent = function (parseClass, handler, validationHandle

ParseCloud._removeAllHooks = () => {
triggers._unregisterAll();
const config = Config.get(Parse.applicationId);
config?.unregisterRateLimiters();
};

ParseCloud.useMasterKey = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -545,6 +545,7 @@ export const addRateLimit = (route, config) => {
},
store: redisStore.store,
}),
cloud,
});
Config.put(config);
};
Expand Down