From 6389b93d275fed953391653b876144a26b805995 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Thu, 18 Feb 2016 20:57:13 -0500 Subject: [PATCH 1/3] tests for troubleshooting #456 --- spec/issue456.spec.js | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 spec/issue456.spec.js diff --git a/spec/issue456.spec.js b/spec/issue456.spec.js new file mode 100644 index 0000000000..ad7bd25986 --- /dev/null +++ b/spec/issue456.spec.js @@ -0,0 +1,100 @@ + + +describe("issue 456", () => { + + it("should properly run promises together", (done) => { + const obj1 = new Parse.Object("ObjectA"); + obj1.set({ + "foo": "bar" + }) + + const obj2 = new Parse.Object("ObjectB"); + obj2.set({ + "bar": "baz" + }); + + Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + done(); + }, function(err){ + fail(err); + done(); + }); + + }) + + it("should properly run query promises together", (done) => { + const obj1 = new Parse.Object("ObjectA"); + obj1.set({ + "foo": "bar" + }) + + const obj2 = new Parse.Object("ObjectB"); + obj2.set({ + "bar": "baz" + }); + + Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + + const q1 = new Parse.Query("ObjectA"); + const q2 = new Parse.Query("ObjectB"); + + return Parse.Promise.when(q1.first(), q2.first()) + + }).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + done(); + }).fail((err) => { + fail(err); + done(); + }); + + }); + + it("should properly run query promises together in cloud code", (done) => { + + Parse.Cloud.define("testRunQueriesTogether", (req, res) => { + const obj1 = new Parse.Object("ObjectA"); + obj1.set({ + "foo": "bar" + }) + + const obj2 = new Parse.Object("ObjectB"); + obj2.set({ + "bar": "baz" + }); + + Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + + const q1 = new Parse.Query("ObjectA"); + const q2 = new Parse.Query("ObjectB"); + + return Parse.Promise.when(q1.first(), q2.first()) + + }).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + res.success([obj1Again, obj2Again]); + }); + }); + + Parse.Cloud.run("testRunQueriesTogether").then( (res) => { + expect(res.length).toBe(2); + expect(res[0].get("foo")).toEqual("bar"); + expect(res[1].get("bar")).toEqual("baz"); + delete Parse.Cloud.Functions['testRunQueriesTogether']; + done(); + }).fail((err) => { + delete Parse.Cloud.Functions['testRunQueriesTogether']; + fail(err); + done(); + }); + + }) +}) \ No newline at end of file From bc5806662247a8ce75bfaf1a2e34ffd1b805efa8 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Thu, 18 Feb 2016 22:08:10 -0500 Subject: [PATCH 2/3] Moved spec in src/cloud/main.js --- spec/issue456.spec.js | 29 ----------------------------- src/cloud/main.js | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/spec/issue456.spec.js b/spec/issue456.spec.js index ad7bd25986..a0304395dd 100644 --- a/spec/issue456.spec.js +++ b/spec/issue456.spec.js @@ -57,41 +57,12 @@ describe("issue 456", () => { it("should properly run query promises together in cloud code", (done) => { - Parse.Cloud.define("testRunQueriesTogether", (req, res) => { - const obj1 = new Parse.Object("ObjectA"); - obj1.set({ - "foo": "bar" - }) - - const obj2 = new Parse.Object("ObjectB"); - obj2.set({ - "bar": "baz" - }); - - Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => { - expect(obj1Again.get("foo")).toEqual("bar"); - expect(obj2Again.get("bar")).toEqual("baz"); - - const q1 = new Parse.Query("ObjectA"); - const q2 = new Parse.Query("ObjectB"); - - return Parse.Promise.when(q1.first(), q2.first()) - - }).then((obj1Again, obj2Again) => { - expect(obj1Again.get("foo")).toEqual("bar"); - expect(obj2Again.get("bar")).toEqual("baz"); - res.success([obj1Again, obj2Again]); - }); - }); - Parse.Cloud.run("testRunQueriesTogether").then( (res) => { expect(res.length).toBe(2); expect(res[0].get("foo")).toEqual("bar"); expect(res[1].get("bar")).toEqual("baz"); - delete Parse.Cloud.Functions['testRunQueriesTogether']; done(); }).fail((err) => { - delete Parse.Cloud.Functions['testRunQueriesTogether']; fail(err); done(); }); diff --git a/src/cloud/main.js b/src/cloud/main.js index fec259910a..90f1a911d4 100644 --- a/src/cloud/main.js +++ b/src/cloud/main.js @@ -102,3 +102,30 @@ Parse.Cloud.define('requiredParameterCheck', function(req, res) { }, function(params) { return params.name; }); + +Parse.Cloud.define("testRunQueriesTogether", (req, res) => { + const obj1 = new Parse.Object("ObjectA"); + obj1.set({ + "foo": "bar" + }) + + const obj2 = new Parse.Object("ObjectB"); + obj2.set({ + "bar": "baz" + }); + + Parse.Promise.when(obj1.save(), obj2.save()).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + + const q1 = new Parse.Query("ObjectA"); + const q2 = new Parse.Query("ObjectB"); + + return Parse.Promise.when(q1.first(), q2.first()) + + }).then((obj1Again, obj2Again) => { + expect(obj1Again.get("foo")).toEqual("bar"); + expect(obj2Again.get("bar")).toEqual("baz"); + res.success([obj1Again, obj2Again]); + }); +}); From 30791e131336714b21e53fbd9453424a80d30d4c Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 19 Feb 2016 08:40:09 -0500 Subject: [PATCH 3/3] Adds heavy test in cloud code for troubleshoot --- spec/issue456.spec.js | 13 +++++++++++++ src/cloud/main.js | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/spec/issue456.spec.js b/spec/issue456.spec.js index a0304395dd..d70c81e09e 100644 --- a/spec/issue456.spec.js +++ b/spec/issue456.spec.js @@ -68,4 +68,17 @@ describe("issue 456", () => { }); }) + + it("should properly run query promises together in cloud code", (done) => { + + Parse.Cloud.run("testCreateManyObjectInParallel").then( (res) => { + expect(res.length).toBe(2); + expect(res[0].length).toBe(200); + expect(res[1].length).toBe(200); + done(); + }).fail((err) => { + fail(err); + done(); + }); + }); }) \ No newline at end of file diff --git a/src/cloud/main.js b/src/cloud/main.js index 90f1a911d4..12fae49955 100644 --- a/src/cloud/main.js +++ b/src/cloud/main.js @@ -129,3 +129,48 @@ Parse.Cloud.define("testRunQueriesTogether", (req, res) => { res.success([obj1Again, obj2Again]); }); }); + +Parse.Cloud.define("testCreateManyObjectInParallel", (req, res) => { + var objects1 = []; + var objects2 = []; + // create 400 objects + for(var i=0; i<200; i++) { + var objA = new Parse.Object("ObjectA"); + var objB = new Parse.Object("ObjectB"); + objA.set({ + index: i + }) + objB.set({ + index: i + }) + objects1.push(objA); + objects2.push(objB); + } + + // Gotta save dem all + var promises = []; + promises.push(Parse.Object.saveAll(objects1)); + promises.push(Parse.Object.saveAll(objects2)); + return Parse.Promise.when(promises).then(function(res){ + if (res.length != 2) { + throw "Should have two results" + } + if (res[0].length != 200) { + throw "Should have saved 200 object on the 1st class" + } + if (res[1].length != 200) { + throw "Should have saved 200 object on the 2nd class" + } + var qA = new Parse.Query("ObjectA"); + var qB = new Parse.Query("ObjectB"); + qA.limit(1000); + qB.limit(1000); + var promises = []; + promises.push(qA.find()); + promises.push(qB.find()); + return Parse.Promise.when(promises); + }).then(function(results){ + res.success(results); + }) + +})