Skip to content

Commit eaa1f10

Browse files
authored
ci: Fix flaky tests (#1668)
1 parent 81607f6 commit eaa1f10

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

integration/test/IdempotencyTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const Parse = require('../../node');
4+
const sleep = require('./sleep');
45

56
const Item = Parse.Object.extend('IdempotencyItem');
67
const RESTController = Parse.CoreManager.getRESTController();
@@ -47,6 +48,13 @@ describe('Idempotency', () => {
4748
'Duplicate request'
4849
);
4950

51+
const checkJobStatus = async () => {
52+
const result = await Parse.Cloud.getJobStatus(jobStatusId);
53+
return result && result.get('status') === 'succeeded';
54+
};
55+
while (!(await checkJobStatus())) {
56+
await sleep(100);
57+
}
5058
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
5159
expect(jobStatus.get('status')).toBe('succeeded');
5260
expect(jobStatus.get('params').startedBy).toBe('Monty Python');

integration/test/ParseCloudTest.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,20 @@ describe('Parse Cloud', () => {
8383
});
8484
});
8585

86-
it('run job', done => {
86+
it('run job', async () => {
8787
const params = { startedBy: 'Monty Python' };
88-
Parse.Cloud.startJob('CloudJob1', params)
89-
.then(jobStatusId => {
90-
return Parse.Cloud.getJobStatus(jobStatusId);
91-
})
92-
.then(jobStatus => {
93-
assert.equal(jobStatus.get('status'), 'succeeded');
94-
assert.equal(jobStatus.get('params').startedBy, 'Monty Python');
95-
done();
96-
});
88+
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params);
89+
90+
const checkJobStatus = async () => {
91+
const result = await Parse.Cloud.getJobStatus(jobStatusId);
92+
return result && result.get('status') === 'succeeded';
93+
};
94+
while (!(await checkJobStatus())) {
95+
await sleep(100);
96+
}
97+
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
98+
assert.equal(jobStatus.get('status'), 'succeeded');
99+
assert.equal(jobStatus.get('params').startedBy, 'Monty Python');
97100
});
98101

99102
it('run long job', async () => {

integration/test/ParseObjectTest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ describe('Parse Object', () => {
16741674
assert.equal(user.createdAt.getTime(), sameUser.createdAt.getTime());
16751675
assert.equal(user.updatedAt.getTime(), sameUser.updatedAt.getTime());
16761676
await Parse.User.logOut();
1677+
Parse.User.disableUnsafeCurrentUser();
16771678
});
16781679

16791680
it('can fetchAllIfNeededWithInclude', async () => {
@@ -2014,7 +2015,7 @@ describe('Parse Object', () => {
20142015
assert.equal(user.isDataAvailable(), true);
20152016

20162017
const query = new Parse.Query(Parse.User);
2017-
const fetched = await query.get(user.id);
2018+
const fetched = await query.get(user.id, { useMasterKey: true });
20182019
assert.equal(fetched.isDataAvailable(), true);
20192020
});
20202021

integration/test/ParseQueryTest.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,15 @@ describe('Parse Query', () => {
23652365
query.hint('_id_');
23662366
query.explain();
23672367
const explain = await query.find();
2368-
assert.equal(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName, '_id_');
2368+
let indexName = '';
2369+
// https://www.mongodb.com/docs/manual/reference/explain-results/#std-label-queryPlanner
2370+
const plan = explain.queryPlanner.winningPlan;
2371+
if (plan.inputStage) {
2372+
indexName = plan.inputStage.inputStage.indexName;
2373+
} else {
2374+
indexName = plan.queryPlan.inputStage.inputStage.indexName;
2375+
}
2376+
assert.equal(indexName, '_id_');
23692377
});
23702378

23712379
it('can query with select on null field', async () => {

integration/test/ParseSchemaTest.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ const defaultCLPS = {
2626
};
2727

2828
describe('Schema', () => {
29+
beforeEach(async () => {
30+
try {
31+
const schemas = await Parse.Schema.all();
32+
for (const result of schemas) {
33+
const schema = new Parse.Schema(result.className);
34+
await schema.purge();
35+
await schema.delete();
36+
}
37+
} catch (_) {
38+
// Schema not found
39+
}
40+
});
41+
2942
it('invalid get all no schema', done => {
3043
Parse.Schema.all()
3144
.then(() => {})

integration/test/ParseUserTest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ describe('Parse User', () => {
185185
});
186186

187187
it('cannot save non-authed user', done => {
188+
Parse.User.enableUnsafeCurrentUser();
188189
let user = new Parse.User();
189190
let notAuthed = null;
190191
user.set({
@@ -220,6 +221,7 @@ describe('Parse User', () => {
220221
});
221222

222223
it('cannot delete non-authed user', done => {
224+
Parse.User.enableUnsafeCurrentUser();
223225
let user = new Parse.User();
224226
let notAuthed = null;
225227
user
@@ -252,6 +254,7 @@ describe('Parse User', () => {
252254
});
253255

254256
it('cannot saveAll with non-authed user', done => {
257+
Parse.User.enableUnsafeCurrentUser();
255258
let user = new Parse.User();
256259
let notAuthed = null;
257260
user
@@ -435,6 +438,7 @@ describe('Parse User', () => {
435438
});
436439

437440
it('can query for users', done => {
441+
Parse.User.enableUnsafeCurrentUser();
438442
const user = new Parse.User();
439443
user.set('password', 'asdf');
440444
user.set('email', '[email protected]');
@@ -457,6 +461,7 @@ describe('Parse User', () => {
457461
});
458462

459463
it('preserves the session token when querying the current user', done => {
464+
Parse.User.enableUnsafeCurrentUser();
460465
const user = new Parse.User();
461466
user.set('password', 'asdf');
462467
user.set('email', '[email protected]');

0 commit comments

Comments
 (0)