Skip to content

Commit 14a8d33

Browse files
authored
FIX: Transaction was aborting before all promises have either resolved or rejected (#5878)
1 parent baa5dae commit 14a8d33

File tree

5 files changed

+360
-43
lines changed

5 files changed

+360
-43
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
"build": "babel src/ -d lib/ --copy-files",
9797
"watch": "babel --watch src/ -d lib/ --copy-files",
9898
"pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner start",
99-
"test": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 jasmine",
99+
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 jasmine",
100+
"test": "npm run testonly",
100101
"posttest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} mongodb-runner stop",
101102
"coverage": "npm run pretest && cross-env MONGODB_VERSION=${MONGODB_VERSION:=4.0.4} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} MONGODB_STORAGE_ENGINE=${MONGODB_STORAGE_ENGINE:=mmapv1} TESTING=1 nyc jasmine && npm run posttest",
102103
"start": "node ./bin/parse-server",

spec/ParseServerRESTController.spec.js

Lines changed: 169 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,90 @@ describe('ParseServerRESTController', () => {
190190
path: '/1/classes/MyObject',
191191
body: { key: 10 },
192192
},
193+
{
194+
method: 'POST',
195+
path: '/1/classes/MyObject',
196+
body: { key: 'value1' },
197+
},
198+
{
199+
method: 'POST',
200+
path: '/1/classes/MyObject',
201+
body: { key: 10 },
202+
},
203+
{
204+
method: 'POST',
205+
path: '/1/classes/MyObject',
206+
body: { key: 'value1' },
207+
},
208+
{
209+
method: 'POST',
210+
path: '/1/classes/MyObject',
211+
body: { key: 10 },
212+
},
213+
{
214+
method: 'POST',
215+
path: '/1/classes/MyObject',
216+
body: { key: 'value1' },
217+
},
218+
{
219+
method: 'POST',
220+
path: '/1/classes/MyObject',
221+
body: { key: 10 },
222+
},
223+
{
224+
method: 'POST',
225+
path: '/1/classes/MyObject',
226+
body: { key: 'value1' },
227+
},
228+
{
229+
method: 'POST',
230+
path: '/1/classes/MyObject',
231+
body: { key: 10 },
232+
},
233+
{
234+
method: 'POST',
235+
path: '/1/classes/MyObject',
236+
body: { key: 'value1' },
237+
},
238+
{
239+
method: 'POST',
240+
path: '/1/classes/MyObject',
241+
body: { key: 10 },
242+
},
243+
{
244+
method: 'POST',
245+
path: '/1/classes/MyObject',
246+
body: { key: 'value1' },
247+
},
248+
{
249+
method: 'POST',
250+
path: '/1/classes/MyObject',
251+
body: { key: 10 },
252+
},
253+
{
254+
method: 'POST',
255+
path: '/1/classes/MyObject',
256+
body: { key: 'value1' },
257+
},
258+
{
259+
method: 'POST',
260+
path: '/1/classes/MyObject',
261+
body: { key: 10 },
262+
},
263+
{
264+
method: 'POST',
265+
path: '/1/classes/MyObject',
266+
body: { key: 'value1' },
267+
},
268+
{
269+
method: 'POST',
270+
path: '/1/classes/MyObject',
271+
body: { key: 10 },
272+
},
193273
],
194274
transaction: true,
195275
}).catch(error => {
196-
expect(error.message).toBeDefined();
276+
expect(error).toBeDefined();
197277
const query = new Parse.Query('MyObject');
198278
query.find().then(results => {
199279
expect(results.length).toBe(0);
@@ -231,6 +311,86 @@ describe('ParseServerRESTController', () => {
231311
path: '/1/classes/MyObject2',
232312
body: { key: 10 },
233313
},
314+
{
315+
method: 'POST',
316+
path: '/1/classes/MyObject2',
317+
body: { key: 'value1' },
318+
},
319+
{
320+
method: 'POST',
321+
path: '/1/classes/MyObject2',
322+
body: { key: 10 },
323+
},
324+
{
325+
method: 'POST',
326+
path: '/1/classes/MyObject2',
327+
body: { key: 'value1' },
328+
},
329+
{
330+
method: 'POST',
331+
path: '/1/classes/MyObject2',
332+
body: { key: 10 },
333+
},
334+
{
335+
method: 'POST',
336+
path: '/1/classes/MyObject2',
337+
body: { key: 'value1' },
338+
},
339+
{
340+
method: 'POST',
341+
path: '/1/classes/MyObject2',
342+
body: { key: 10 },
343+
},
344+
{
345+
method: 'POST',
346+
path: '/1/classes/MyObject2',
347+
body: { key: 'value1' },
348+
},
349+
{
350+
method: 'POST',
351+
path: '/1/classes/MyObject2',
352+
body: { key: 10 },
353+
},
354+
{
355+
method: 'POST',
356+
path: '/1/classes/MyObject2',
357+
body: { key: 'value1' },
358+
},
359+
{
360+
method: 'POST',
361+
path: '/1/classes/MyObject2',
362+
body: { key: 10 },
363+
},
364+
{
365+
method: 'POST',
366+
path: '/1/classes/MyObject2',
367+
body: { key: 'value1' },
368+
},
369+
{
370+
method: 'POST',
371+
path: '/1/classes/MyObject2',
372+
body: { key: 10 },
373+
},
374+
{
375+
method: 'POST',
376+
path: '/1/classes/MyObject2',
377+
body: { key: 'value1' },
378+
},
379+
{
380+
method: 'POST',
381+
path: '/1/classes/MyObject2',
382+
body: { key: 10 },
383+
},
384+
{
385+
method: 'POST',
386+
path: '/1/classes/MyObject2',
387+
body: { key: 'value1' },
388+
},
389+
{
390+
method: 'POST',
391+
path: '/1/classes/MyObject2',
392+
body: { key: 10 },
393+
},
234394
],
235395
transaction: true,
236396
});
@@ -296,13 +456,13 @@ describe('ParseServerRESTController', () => {
296456
'value2',
297457
]);
298458

299-
expect(databaseAdapter.createObject.calls.count()).toBe(5);
459+
expect(databaseAdapter.createObject.calls.count()).toBe(13);
300460
let transactionalSession;
301461
let transactionalSession2;
302462
let myObjectDBCalls = 0;
303463
let myObject2DBCalls = 0;
304464
let myObject3DBCalls = 0;
305-
for (let i = 0; i < 5; i++) {
465+
for (let i = 0; i < 13; i++) {
306466
const args = databaseAdapter.createObject.calls.argsFor(i);
307467
switch (args[0]) {
308468
case 'MyObject':
@@ -318,7 +478,11 @@ describe('ParseServerRESTController', () => {
318478
break;
319479
case 'MyObject2':
320480
myObject2DBCalls++;
321-
transactionalSession2 = args[3];
481+
if (!transactionalSession2) {
482+
transactionalSession2 = args[3];
483+
} else {
484+
expect(transactionalSession2).toBe(args[3]);
485+
}
322486
if (transactionalSession) {
323487
expect(transactionalSession).not.toBe(args[3]);
324488
}
@@ -330,7 +494,7 @@ describe('ParseServerRESTController', () => {
330494
}
331495
}
332496
expect(myObjectDBCalls).toEqual(2);
333-
expect(myObject2DBCalls).toEqual(1);
497+
expect(myObject2DBCalls).toEqual(9);
334498
expect(myObject3DBCalls).toEqual(2);
335499
});
336500
});

0 commit comments

Comments
 (0)