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 due to open server connection #1670

Merged
merged 6 commits into from
Jan 27, 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
43 changes: 19 additions & 24 deletions integration/test/ParseCloudTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ const assert = require('assert');
const Parse = require('../../node');
const sleep = require('./sleep');

const waitForJobStatus = async (jobStatusId, status) => {
const checkJobStatus = async () => {
const result = await Parse.Cloud.getJobStatus(jobStatusId);
return result && result.get('status') === status;
};
while (!(await checkJobStatus())) {
await sleep(100);
}
};

describe('Parse Cloud', () => {
it('run function', done => {
const params = { key1: 'value2', key2: 'value1' };
Expand Down Expand Up @@ -86,14 +96,8 @@ describe('Parse Cloud', () => {
it('run job', async () => {
const params = { startedBy: 'Monty Python' };
const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params);
await waitForJobStatus(jobStatusId, 'succeeded');

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');
Expand All @@ -104,14 +108,8 @@ describe('Parse Cloud', () => {

let jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
assert.equal(jobStatus.get('status'), 'running');
await waitForJobStatus(jobStatusId, 'succeeded');

const checkJobStatus = async () => {
const result = await Parse.Cloud.getJobStatus(jobStatusId);
return result && result.get('status') === 'succeeded';
};
while (!(await checkJobStatus())) {
await sleep(100);
}
jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
assert.equal(jobStatus.get('status'), 'succeeded');
});
Expand All @@ -126,16 +124,13 @@ describe('Parse Cloud', () => {
});
});

it('run failing job', done => {
Parse.Cloud.startJob('CloudJobFailing')
.then(jobStatusId => {
return Parse.Cloud.getJobStatus(jobStatusId);
})
.then(jobStatus => {
assert.equal(jobStatus.get('status'), 'failed');
assert.equal(jobStatus.get('message'), 'cloud job failed');
done();
});
it('run failing job', async () => {
const jobStatusId = await Parse.Cloud.startJob('CloudJobFailing');
await waitForJobStatus(jobStatusId, 'failed');

const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId);
assert.equal(jobStatus.get('status'), 'failed');
assert.equal(jobStatus.get('message'), 'cloud job failed');
});

it('get jobs data', done => {
Expand Down
18 changes: 13 additions & 5 deletions integration/test/ParseDistTest.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const puppeteer = require('puppeteer');
let browser = null;
let page = null;
for (const fileName of ['parse.js', 'parse.min.js']) {
beforeAll(async () => {
const browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto(`http://localhost:1337/${fileName}`);
});
describe(`Parse Dist Test ${fileName}`, () => {
beforeEach(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto(`http://localhost:1337/${fileName}`);
});

afterEach(async () => {
await page.close();
await browser.close();
});

it('can save an object', async () => {
const response = await page.evaluate(async () => {
const object = await new Parse.Object('TestObject').save();
Expand All @@ -17,6 +24,7 @@ for (const fileName of ['parse.js', 'parse.min.js']) {
expect(obj).toBeDefined();
expect(obj.id).toEqual(response);
});

it('can query an object', async () => {
const obj = await new Parse.Object('TestObject').save();
const response = await page.evaluate(async () => {
Expand Down
7 changes: 5 additions & 2 deletions integration/test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ beforeAll(async () => {

afterEach(async () => {
await Parse.User.logOut();
// Connection close events are not immediate on node 10+... wait a bit
await sleep(0);
if (Object.keys(openConnections).length > 0) {
console.warn('There were open connections to the server left after the test finished');
}
Parse.Storage._clear();
await TestUtils.destroyAllDataPermanently(true);
destroyAliveConnections();
// Connection close events are not immediate on node 10+... wait a bit
await sleep(0);
if (didChangeConfiguration) {
await reconfigureServer();
}
Expand Down