Skip to content

ci: Fix flaky tests #1668

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

Merged
merged 6 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions integration/test/IdempotencyTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Parse = require('../../node');
const sleep = require('./sleep');

const Item = Parse.Object.extend('IdempotencyItem');
const RESTController = Parse.CoreManager.getRESTController();
Expand Down Expand Up @@ -47,6 +48,13 @@ describe('Idempotency', () => {
'Duplicate request'
);

const checkJobStatus = async () => {
const result = await Parse.Cloud.getJobStatus(jobStatusId);
return result && result.get('status') === 'succeeded';
};
while (!(await checkJobStatus())) {
await sleep(100);
}
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
expect(jobStatus.get('status')).toBe('succeeded');
expect(jobStatus.get('params').startedBy).toBe('Monty Python');
Expand Down
23 changes: 13 additions & 10 deletions integration/test/ParseCloudTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,20 @@ describe('Parse Cloud', () => {
});
});

it('run job', done => {
it('run job', async () => {
const params = { startedBy: 'Monty Python' };
Parse.Cloud.startJob('CloudJob1', params)
.then(jobStatusId => {
return Parse.Cloud.getJobStatus(jobStatusId);
})
.then(jobStatus => {
assert.equal(jobStatus.get('status'), 'succeeded');
assert.equal(jobStatus.get('params').startedBy, 'Monty Python');
done();
});
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params);

const checkJobStatus = async () => {
const result = await Parse.Cloud.getJobStatus(jobStatusId);
return result && result.get('status') === 'succeeded';
};
while (!(await checkJobStatus())) {
await sleep(100);
}
const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
assert.equal(jobStatus.get('status'), 'succeeded');
assert.equal(jobStatus.get('params').startedBy, 'Monty Python');
});

it('run long job', async () => {
Expand Down
3 changes: 2 additions & 1 deletion integration/test/ParseObjectTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ describe('Parse Object', () => {
assert.equal(user.createdAt.getTime(), sameUser.createdAt.getTime());
assert.equal(user.updatedAt.getTime(), sameUser.updatedAt.getTime());
await Parse.User.logOut();
Parse.User.disableUnsafeCurrentUser();
});

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

const query = new Parse.Query(Parse.User);
const fetched = await query.get(user.id);
const fetched = await query.get(user.id, { useMasterKey: true });
assert.equal(fetched.isDataAvailable(), true);
});

Expand Down
10 changes: 9 additions & 1 deletion integration/test/ParseQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,15 @@ describe('Parse Query', () => {
query.hint('_id_');
query.explain();
const explain = await query.find();
assert.equal(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName, '_id_');
let indexName = '';
// https://www.mongodb.com/docs/manual/reference/explain-results/#std-label-queryPlanner
const plan = explain.queryPlanner.winningPlan;
if (plan.inputStage) {
indexName = plan.inputStage.inputStage.indexName;
} else {
indexName = plan.queryPlan.inputStage.inputStage.indexName;
}
assert.equal(indexName, '_id_');
});

it('can query with select on null field', async () => {
Expand Down
13 changes: 13 additions & 0 deletions integration/test/ParseSchemaTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ const defaultCLPS = {
};

describe('Schema', () => {
beforeEach(async () => {
try {
const schemas = await Parse.Schema.all();
for (const result of schemas) {
const schema = new Parse.Schema(result.className);
await schema.purge();
await schema.delete();
}
} catch (_) {
// Schema not found
}
});

it('invalid get all no schema', done => {
Parse.Schema.all()
.then(() => {})
Expand Down
5 changes: 5 additions & 0 deletions integration/test/ParseUserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe('Parse User', () => {
});

it('cannot save non-authed user', done => {
Parse.User.enableUnsafeCurrentUser();
let user = new Parse.User();
let notAuthed = null;
user.set({
Expand Down Expand Up @@ -220,6 +221,7 @@ describe('Parse User', () => {
});

it('cannot delete non-authed user', done => {
Parse.User.enableUnsafeCurrentUser();
let user = new Parse.User();
let notAuthed = null;
user
Expand Down Expand Up @@ -252,6 +254,7 @@ describe('Parse User', () => {
});

it('cannot saveAll with non-authed user', done => {
Parse.User.enableUnsafeCurrentUser();
let user = new Parse.User();
let notAuthed = null;
user
Expand Down Expand Up @@ -435,6 +438,7 @@ describe('Parse User', () => {
});

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

it('preserves the session token when querying the current user', done => {
Parse.User.enableUnsafeCurrentUser();
const user = new Parse.User();
user.set('password', 'asdf');
user.set('email', '[email protected]');
Expand Down