From 7747a7650c0c1b425d4d1cbe0b836d2ddc83a3af Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 25 Jan 2023 17:55:10 -0600 Subject: [PATCH 1/6] fix: Flaky test --- integration/test/ParseCloudTest.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/integration/test/ParseCloudTest.js b/integration/test/ParseCloudTest.js index 8ec1702b1..e99845974 100644 --- a/integration/test/ParseCloudTest.js +++ b/integration/test/ParseCloudTest.js @@ -83,17 +83,20 @@ describe('Parse Cloud', () => { }); }); - it('run job', done => { + it('run job', async () => { const params = { startedBy: 'Monty Python' }; - Parse.Cloud.startJob('CloudJob1', params) - .then(jobStatusId => { - return Parse.Cloud.getJobStatus(jobStatusId); - }) - .then(jobStatus => { - assert.equal(jobStatus.get('status'), 'succeeded'); - assert.equal(jobStatus.get('params').startedBy, 'Monty Python'); - done(); - }); + const jobStatusId = await Parse.Cloud.startJob('CloudJob1', params); + + const checkJobStatus = async () => { + const result = await Parse.Cloud.getJobStatus(jobStatusId); + return result && result.get('status') === 'succeeded'; + }; + while (!(await checkJobStatus())) { + await sleep(100); + } + const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); + assert.equal(jobStatus.get('status'), 'succeeded'); + assert.equal(jobStatus.get('params').startedBy, 'Monty Python'); }); it('run long job', async () => { From 2d9a0f2e4f631c35fe51ef693d0d2c41bc009bd4 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 25 Jan 2023 19:04:08 -0600 Subject: [PATCH 2/6] handle schema tests --- integration/test/ParseSchemaTest.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/integration/test/ParseSchemaTest.js b/integration/test/ParseSchemaTest.js index 777bf0cb1..e9b23e7ed 100644 --- a/integration/test/ParseSchemaTest.js +++ b/integration/test/ParseSchemaTest.js @@ -26,6 +26,19 @@ const defaultCLPS = { }; describe('Schema', () => { + beforeEach(async () => { + try { + const schemas = await Parse.Schema.all(); + for (const result of schemas) { + const schema = new Parse.Schema(result.className); + await schema.purge(); + await schema.delete(); + } + } catch (_) { + // Schema not found + } + }); + it('invalid get all no schema', done => { Parse.Schema.all() .then(() => {}) From 682aa32aca661190729e4d84abdd5ea5a2f0940f Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 25 Jan 2023 19:28:10 -0600 Subject: [PATCH 3/6] fix user tests --- integration/test/ParseObjectTest.js | 3 ++- integration/test/ParseUserTest.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/integration/test/ParseObjectTest.js b/integration/test/ParseObjectTest.js index c5849ed74..c8e1c7bbd 100644 --- a/integration/test/ParseObjectTest.js +++ b/integration/test/ParseObjectTest.js @@ -1674,6 +1674,7 @@ describe('Parse Object', () => { assert.equal(user.createdAt.getTime(), sameUser.createdAt.getTime()); assert.equal(user.updatedAt.getTime(), sameUser.updatedAt.getTime()); await Parse.User.logOut(); + Parse.User.disableUnsafeCurrentUser(); }); it('can fetchAllIfNeededWithInclude', async () => { @@ -2014,7 +2015,7 @@ describe('Parse Object', () => { assert.equal(user.isDataAvailable(), true); const query = new Parse.Query(Parse.User); - const fetched = await query.get(user.id); + const fetched = await query.get(user.id, { useMasterKey: true }); assert.equal(fetched.isDataAvailable(), true); }); diff --git a/integration/test/ParseUserTest.js b/integration/test/ParseUserTest.js index f32c0cb5d..82bea335a 100644 --- a/integration/test/ParseUserTest.js +++ b/integration/test/ParseUserTest.js @@ -252,6 +252,7 @@ describe('Parse User', () => { }); it('cannot saveAll with non-authed user', done => { + Parse.User.enableUnsafeCurrentUser(); let user = new Parse.User(); let notAuthed = null; user From 9858994c30f41c605649dac3228165e1019eb06a Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 25 Jan 2023 19:44:46 -0600 Subject: [PATCH 4/6] more user tests --- integration/test/ParseUserTest.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration/test/ParseUserTest.js b/integration/test/ParseUserTest.js index 82bea335a..66d0e5003 100644 --- a/integration/test/ParseUserTest.js +++ b/integration/test/ParseUserTest.js @@ -185,6 +185,7 @@ describe('Parse User', () => { }); it('cannot save non-authed user', done => { + Parse.User.enableUnsafeCurrentUser(); let user = new Parse.User(); let notAuthed = null; user.set({ @@ -220,6 +221,7 @@ describe('Parse User', () => { }); it('cannot delete non-authed user', done => { + Parse.User.enableUnsafeCurrentUser(); let user = new Parse.User(); let notAuthed = null; user @@ -436,6 +438,7 @@ describe('Parse User', () => { }); it('can query for users', done => { + Parse.User.enableUnsafeCurrentUser(); const user = new Parse.User(); user.set('password', 'asdf'); user.set('email', 'asdf@exxample.com'); @@ -458,6 +461,7 @@ describe('Parse User', () => { }); it('preserves the session token when querying the current user', done => { + Parse.User.enableUnsafeCurrentUser(); const user = new Parse.User(); user.set('password', 'asdf'); user.set('email', 'asdf@example.com'); From 04ceede4105113d866d06723f379426f446f192c Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 25 Jan 2023 20:29:06 -0600 Subject: [PATCH 5/6] Update IdempotencyTest.js --- integration/test/IdempotencyTest.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/integration/test/IdempotencyTest.js b/integration/test/IdempotencyTest.js index 61104f971..ed0147d4c 100644 --- a/integration/test/IdempotencyTest.js +++ b/integration/test/IdempotencyTest.js @@ -1,6 +1,7 @@ 'use strict'; const Parse = require('../../node'); +const sleep = require('./sleep'); const Item = Parse.Object.extend('IdempotencyItem'); const RESTController = Parse.CoreManager.getRESTController(); @@ -47,6 +48,13 @@ describe('Idempotency', () => { 'Duplicate request' ); + const checkJobStatus = async () => { + const result = await Parse.Cloud.getJobStatus(jobStatusId); + return result && result.get('status') === 'succeeded'; + }; + while (!(await checkJobStatus())) { + await sleep(100); + } const jobStatus = await Parse.Cloud.getJobStatus(jobStatusId); expect(jobStatus.get('status')).toBe('succeeded'); expect(jobStatus.get('params').startedBy).toBe('Monty Python'); From 9a10aae42e50835e2607cfaf0cd6fdf191e7038f Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Thu, 26 Jan 2023 01:00:26 -0600 Subject: [PATCH 6/6] fix query explain test --- integration/test/ParseQueryTest.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/integration/test/ParseQueryTest.js b/integration/test/ParseQueryTest.js index 149c2e537..112bd54c9 100644 --- a/integration/test/ParseQueryTest.js +++ b/integration/test/ParseQueryTest.js @@ -2365,7 +2365,15 @@ describe('Parse Query', () => { query.hint('_id_'); query.explain(); const explain = await query.find(); - assert.equal(explain.queryPlanner.winningPlan.inputStage.inputStage.indexName, '_id_'); + let indexName = ''; + // https://www.mongodb.com/docs/manual/reference/explain-results/#std-label-queryPlanner + const plan = explain.queryPlanner.winningPlan; + if (plan.inputStage) { + indexName = plan.inputStage.inputStage.indexName; + } else { + indexName = plan.queryPlan.inputStage.inputStage.indexName; + } + assert.equal(indexName, '_id_'); }); it('can query with select on null field', async () => {