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

test: Add test for incrementing number atomically #8789

Open
wants to merge 14 commits into
base: alpha
Choose a base branch
from
24 changes: 24 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2055,4 +2055,28 @@ describe('Parse.Object testing', () => {
const object = new Parse.Object('CloudCodeIsNew');
await object.save();
});
fit('regression test for #8772 (increment should be atomic)', async () => {
theolundqvist marked this conversation as resolved.
Show resolved Hide resolved
Parse.Object.disableSingleInstance();

mtrezza marked this conversation as resolved.
Show resolved Hide resolved
Parse.Cloud.beforeSave('Parent', (req) => {});
Parse.Cloud.beforeSave('Child', async (req) => {
await req.object.get("parent").increment("num_child").save(null, {useMasterKey:true})
});

let parent = await new Parse.Object('Parent').save(null, {useMasterKey:true});

mtrezza marked this conversation as resolved.
Show resolved Hide resolved
const child = () => new Parse.Object('Child').set("parent",parent).save();

// add synchronously
await child()
await child()
parent = await parent.fetch();
expect(parent.get('num_child')).toBe(2);

// add asynchronously
await Promise.all(Array.from({length: 40}, () => child()))
parent = await parent.fetch();

mtrezza marked this conversation as resolved.
Show resolved Hide resolved
expect(parent.get('num_child')).toBe(42);
});
});
2 changes: 2 additions & 0 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,7 @@ describe('schemas', () => {
});
});


mtrezza marked this conversation as resolved.
Show resolved Hide resolved
it('regression test for #1991', done => {
const user = new Parse.User();
user.setUsername('user');
Expand Down Expand Up @@ -2741,6 +2742,7 @@ describe('schemas', () => {
expect(objectAgain.get('key')).toBe(11);
});


mtrezza marked this conversation as resolved.
Show resolved Hide resolved
it('regression test for #2246', done => {
const profile = new Parse.Object('UserProfile');
const user = new Parse.User();
Expand Down