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
23 changes: 23 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2055,4 +2055,27 @@ describe('Parse.Object testing', () => {
const object = new Parse.Object('CloudCodeIsNew');
await object.save();
});

it('increments atomically', async () => {
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});
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();
expect(parent.get('num_child')).toBe(42);
});
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
});
Loading