Skip to content

Commit

Permalink
Fix error when a not yet inserted job is updated (#7196)
Browse files Browse the repository at this point in the history
* Fix error when a not yet inserted job is updated

* Add entry to changelog

* revert the upsert change and fix the test

* Revert the change so job execute a single time

* Fix other tests with potential similar problem
  • Loading branch information
davimacedo authored Feb 18, 2021
1 parent 9c100cf commit 603cc1f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ___
- IMPROVE: Parse Server is from now on continuously tested against all recent Node.js versions that have not reached their end-of-life support date. [7161](https://github.com/parse-community/parse-server/pull/7177). Thanks to [Manuel Trezza](https://github.com/mtrezza).
- IMPROVE: Optimize queries on classes with pointer permissions. [#7061](https://github.com/parse-community/parse-server/pull/7061). Thanks to [Pedro Diaz](https://github.com/pdiaz)
- IMPROVE: Parse Server will from now on be continuously tested against all relevant Postgres versions (minor versions). Added Postgres compatibility table to Parse Server docs. [#7176](https://github.com/parse-community/parse-server/pull/7176). Thanks to [Corey Baker](https://github.com/cbaker6).
- FIX: Fix error when a not yet inserted job is updated [#7196](https://github.com/parse-community/parse-server/pull/7196). Thanks to [Antonio Davi Macedo Coelho de Castro](https://github.com/davimacedo).
- FIX: request.context for afterFind triggers. [#7078](https://github.com/parse-community/parse-server/pull/7078). Thanks to [dblythy](https://github.com/dblythy)
- FIX: Winston Logger interpolating stdout to console [#7114](https://github.com/parse-community/parse-server/pull/7114). Thanks to [dplewis](https://github.com/dplewis)

Expand Down
151 changes: 79 additions & 72 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,9 @@ describe('Cloud Code', () => {
describe('cloud jobs', () => {
it('should define a job', done => {
expect(() => {
Parse.Cloud.job('myJob', () => {});
Parse.Cloud.job('myJob', ({ message }) => {
message('Hello, world!!!');
});
}).not.toThrow();

request({
Expand All @@ -1559,15 +1561,19 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {
done();
},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return jobStatus.get('finishedAt') && jobStatus.get('message') === 'Hello, world!!!';
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should not run without master key', done => {
Expand Down Expand Up @@ -1602,7 +1608,6 @@ describe('Cloud Code', () => {
expect(typeof req.jobId).toBe('string');
expect(typeof req.message).toBe('function');
expect(typeof res).toBe('undefined');
done();
});
}).not.toThrow();

Expand All @@ -1613,13 +1618,19 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return jobStatus.get('finishedAt');
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should run with master key basic auth', done => {
Expand All @@ -1630,25 +1641,30 @@ describe('Cloud Code', () => {
expect(typeof req.jobId).toBe('string');
expect(typeof req.message).toBe('function');
expect(typeof res).toBe('undefined');
done();
});
}).not.toThrow();

request({
method: 'POST',
url: `http://${Parse.applicationId}:${Parse.masterKey}@localhost:8378/1/jobs/myJob`,
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return jobStatus.get('finishedAt');
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should set the message / success on the job', done => {
Parse.Cloud.job('myJob', req => {
const promise = req
return req
.message('hello')
.then(() => {
return getJobStatus(req.jobId);
Expand All @@ -1657,21 +1673,6 @@ describe('Cloud Code', () => {
expect(jobStatus.get('message')).toEqual('hello');
expect(jobStatus.get('status')).toEqual('running');
});
promise
.then(() => {
return getJobStatus(req.jobId);
})
.then(jobStatus => {
expect(jobStatus.get('message')).toEqual('hello');
expect(jobStatus.get('status')).toEqual('succeeded');
done();
})
.catch(err => {
console.error(err);
jfail(err);
done();
});
return promise;
});

request({
Expand All @@ -1681,32 +1682,28 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return (
jobStatus.get('finishedAt') &&
jobStatus.get('message') === 'hello' &&
jobStatus.get('status') === 'succeeded'
);
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should set the failure on the job', done => {
Parse.Cloud.job('myJob', req => {
const promise = Promise.reject('Something went wrong');
new Promise(resolve => setTimeout(resolve, 200))
.then(() => {
return getJobStatus(req.jobId);
})
.then(jobStatus => {
expect(jobStatus.get('message')).toEqual('Something went wrong');
expect(jobStatus.get('status')).toEqual('failed');
done();
})
.catch(err => {
jfail(err);
done();
});
return promise;
Parse.Cloud.job('myJob', () => {
return Promise.reject('Something went wrong');
});

request({
Expand All @@ -1716,13 +1713,23 @@ describe('Cloud Code', () => {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-Master-Key': Parse.masterKey,
},
}).then(
() => {},
err => {
fail(err);
done();
}
);
})
.then(async response => {
const jobStatusId = response.headers['x-parse-job-status-id'];
const checkJobStatus = async () => {
const jobStatus = await getJobStatus(jobStatusId);
return (
jobStatus.get('finishedAt') &&
jobStatus.get('message') === 'Something went wrong' &&
jobStatus.get('status') === 'failed'
);
};
while (!(await checkJobStatus())) {
await new Promise(resolve => setTimeout(resolve, 100));
}
})
.then(done)
.catch(done.fail);
});

it('should set the failure message on the job error', async () => {
Expand Down

0 comments on commit 603cc1f

Please sign in to comment.