Skip to content

Commit 65e5879

Browse files
authored
ci: Fix flaky tests (#8468)
1 parent cf1b59e commit 65e5879

10 files changed

+44
-15
lines changed

spec/AuthenticationAdaptersV2.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ describe('Auth Adapter features', () => {
348348
it('should strip out authData if required', async () => {
349349
const spy = spyOn(modernAdapter3, 'validateOptions').and.callThrough();
350350
const afterSpy = spyOn(modernAdapter3, 'afterFind').and.callThrough();
351-
await reconfigureServer({ auth: { modernAdapter3 }, silent: false });
351+
await reconfigureServer({ auth: { modernAdapter3 } });
352352
const user = new Parse.User();
353353
await user.save({ authData: { modernAdapter3: { id: 'modernAdapter3Data' } } });
354354
await user.fetch({ sessionToken: user.getSessionToken() });

spec/Idempotency.spec.js

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ describe('Idempotency', () => {
4545
});
4646
});
4747

48-
afterAll(() => {
49-
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
50-
});
51-
5248
// Tests
5349
it('should enforce idempotency for cloud code function', async () => {
5450
let counter = 0;

spec/ParseLiveQueryRedis.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {
66
});
77
it('can connect', async () => {
88
await reconfigureServer({
9+
appId: 'redis_live_query',
910
startLiveQueryServer: true,
1011
liveQuery: {
1112
classNames: ['TestObject'],
@@ -36,6 +37,7 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {
3637

3738
it('can call connect twice', async () => {
3839
const server = await reconfigureServer({
40+
appId: 'redis_live_query',
3941
startLiveQueryServer: true,
4042
liveQuery: {
4143
classNames: ['TestObject'],

spec/ParseLiveQueryServer.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ describe('ParseLiveQueryServer', function () {
115115
});
116116

117117
describe_only_db('mongo')('initialization', () => {
118+
beforeEach(() => reconfigureServer({ appId: 'mongo_init_test' }));
118119
it('can be initialized through ParseServer without liveQueryServerOptions', async () => {
119120
const parseServer = await ParseServer.startApp({
120121
appId: 'hello',

spec/helper.js

+5
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ beforeAll(async () => {
198198
Parse.serverURL = 'http://localhost:' + port + '/1';
199199
});
200200

201+
beforeEach(() => {
202+
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
203+
});
204+
201205
afterEach(function (done) {
202206
const afterLogOut = async () => {
203207
if (Object.keys(openConnections).length > 0) {
@@ -214,6 +218,7 @@ afterEach(function (done) {
214218
done();
215219
};
216220
Parse.Cloud._removeAllHooks();
221+
Parse.CoreManager.getLiveQueryController().setDefaultLiveQueryClient();
217222
defaults.protectedFields = { _User: { '*': ['email'] } };
218223
databaseAdapter
219224
.getAllClasses()

spec/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ describe('server', () => {
558558
});
559559

560560
it('can get starting state', async () => {
561-
await reconfigureServer({ appId: 'test2', silent: false });
561+
await reconfigureServer({ appId: 'test2' });
562562
const parseServer = new ParseServer.ParseServer({
563563
...defaultConfiguration,
564564
appId: 'test2',

src/Config.js

+10
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,16 @@ export class Config {
626626
return new Date(now.getTime() + this.sessionLength * 1000);
627627
}
628628

629+
unregisterRateLimiters() {
630+
let i = this.rateLimits?.length;
631+
while (i--) {
632+
const limit = this.rateLimits[i];
633+
if (limit.cloud) {
634+
this.rateLimits.splice(i, 1);
635+
}
636+
}
637+
}
638+
629639
get invalidLinkURL() {
630640
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
631641
}

src/TestUtils.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AppCache from './cache';
2+
import SchemaCache from './Adapters/Cache/SchemaCache';
23

34
/**
45
* Destroys all data in the database
@@ -11,11 +12,17 @@ export function destroyAllDataPermanently(fast) {
1112
return Promise.all(
1213
Object.keys(AppCache.cache).map(appId => {
1314
const app = AppCache.get(appId);
15+
const deletePromises = [];
16+
if (app.cacheAdapter) {
17+
deletePromises.push(app.cacheAdapter.clear());
18+
}
1419
if (app.databaseController) {
15-
return app.databaseController.deleteEverything(fast);
16-
} else {
17-
return Promise.resolve();
20+
deletePromises.push(app.databaseController.deleteEverything(fast));
21+
} else if (app.databaseAdapter) {
22+
SchemaCache.clear();
23+
deletePromises.push(app.databaseAdapter.deleteAllClasses(fast));
1824
}
25+
return Promise.all(deletePromises);
1926
})
2027
);
2128
}

src/cloud-code/Parse.Cloud.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ ParseCloud.define = function (functionName, handler, validationHandler) {
128128
if (validationHandler && validationHandler.rateLimit) {
129129
addRateLimit(
130130
{ requestPath: `/functions/${functionName}`, ...validationHandler.rateLimit },
131-
Parse.applicationId
131+
Parse.applicationId,
132+
true
132133
);
133134
}
134135
};
@@ -191,7 +192,8 @@ ParseCloud.beforeSave = function (parseClass, handler, validationHandler) {
191192
requestMethods: ['POST', 'PUT'],
192193
...validationHandler.rateLimit,
193194
},
194-
Parse.applicationId
195+
Parse.applicationId,
196+
true
195197
);
196198
}
197199
};
@@ -237,7 +239,8 @@ ParseCloud.beforeDelete = function (parseClass, handler, validationHandler) {
237239
requestMethods: 'DELETE',
238240
...validationHandler.rateLimit,
239241
},
240-
Parse.applicationId
242+
Parse.applicationId,
243+
true
241244
);
242245
}
243246
};
@@ -278,7 +281,8 @@ ParseCloud.beforeLogin = function (handler, validationHandler) {
278281
if (validationHandler && validationHandler.rateLimit) {
279282
addRateLimit(
280283
{ requestPath: `/login`, requestMethods: 'POST', ...validationHandler.rateLimit },
281-
Parse.applicationId
284+
Parse.applicationId,
285+
true
282286
);
283287
}
284288
};
@@ -456,7 +460,8 @@ ParseCloud.beforeFind = function (parseClass, handler, validationHandler) {
456460
requestMethods: 'GET',
457461
...validationHandler.rateLimit,
458462
},
459-
Parse.applicationId
463+
Parse.applicationId,
464+
true
460465
);
461466
}
462467
};
@@ -761,6 +766,8 @@ ParseCloud.afterLiveQueryEvent = function (parseClass, handler, validationHandle
761766

762767
ParseCloud._removeAllHooks = () => {
763768
triggers._unregisterAll();
769+
const config = Config.get(Parse.applicationId);
770+
config?.unregisterRateLimiters();
764771
};
765772

766773
ParseCloud.useMasterKey = () => {

src/middlewares.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export function promiseEnforceMasterKeyAccess(request) {
466466
return Promise.resolve();
467467
}
468468

469-
export const addRateLimit = (route, config) => {
469+
export const addRateLimit = (route, config, cloud) => {
470470
if (typeof config === 'string') {
471471
config = Config.get(config);
472472
}
@@ -545,6 +545,7 @@ export const addRateLimit = (route, config) => {
545545
},
546546
store: redisStore.store,
547547
}),
548+
cloud,
548549
});
549550
Config.put(config);
550551
};

0 commit comments

Comments
 (0)