From f32cc46cd5fbe1a10f82b3cee64c2f1f60e0ceb3 Mon Sep 17 00:00:00 2001 From: Arthur Cinader Date: Mon, 30 Jan 2017 11:38:55 -0800 Subject: [PATCH] Two tests that fail often. Give em a little more time. --- spec/CloudCodeLogger.spec.js | 3 ++- spec/ParseHooks.spec.js | 27 ++++++++++++++------------- spec/ParseInstallation.spec.js | 9 ++++++++- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/spec/CloudCodeLogger.spec.js b/spec/CloudCodeLogger.spec.js index 8a0cd92fb5..54a4d1da5d 100644 --- a/spec/CloudCodeLogger.spec.js +++ b/spec/CloudCodeLogger.spec.js @@ -156,8 +156,9 @@ describe("Cloud Code Logger", () => { .save() .then( () => done.fail('this is not supposed to succeed'), - () => logController.getLogs({ from: Date.now() - 500, size: 1000 }) + () => new Promise(resolve => setTimeout(resolve, 100)) ) + .then(() => logController.getLogs({ from: Date.now() - 500, size: 1000 })) .then(logs => { const log = logs[1]; // 0 is the 'uh oh!' from rejection... expect(log.level).toEqual('error'); diff --git a/spec/ParseHooks.spec.js b/spec/ParseHooks.spec.js index 921cad6fe1..7a3e1095b7 100644 --- a/spec/ParseHooks.spec.js +++ b/spec/ParseHooks.spec.js @@ -143,7 +143,9 @@ describe('Hooks', () => { }); it("should fail trying to create two times the same function", (done) => { - Parse.Hooks.createFunction("my_new_function", "http://url.com").then(() => { + Parse.Hooks.createFunction("my_new_function", "http://url.com") + .then(() => new Promise(resolve => setTimeout(resolve, 100))) + .then(() => { return Parse.Hooks.createFunction("my_new_function", "http://url.com") }, () => { fail("should create a new function"); @@ -421,8 +423,8 @@ describe('Hooks', () => { // But this should override the key upon return res.json({success: object}); }); - // The function is delete as the DB is dropped between calls - Parse.Hooks.createTrigger("SomeRandomObject", "beforeSave" ,hookServerURL + "/BeforeSaveSome").then(function(){ + // The function is deleted as the DB is dropped between calls + Parse.Hooks.createTrigger("SomeRandomObject", "beforeSave", hookServerURL + "/BeforeSaveSome").then(function () { const obj = new Parse.Object("SomeRandomObject"); return obj.save(); }).then(function(res) { @@ -444,7 +446,7 @@ describe('Hooks', () => { object.set('hello', "world"); res.json({success: object}); }); - Parse.Hooks.createTrigger("SomeRandomObject2", "beforeSave" ,hookServerURL + "/BeforeSaveSome2").then(function(){ + Parse.Hooks.createTrigger("SomeRandomObject2", "beforeSave", hookServerURL + "/BeforeSaveSome2").then(function(){ const obj = new Parse.Object("SomeRandomObject2"); return obj.save(); }).then(function(res) { @@ -470,20 +472,19 @@ describe('Hooks', () => { res.json({success: {}}); }) }); - // The function is delete as the DB is dropped between calls - Parse.Hooks.createTrigger("SomeRandomObject", "afterSave" ,hookServerURL + "/AfterSaveSome").then(function(){ + // The function is deleted as the DB is dropped between calls + Parse.Hooks.createTrigger("SomeRandomObject", "afterSave", hookServerURL + "/AfterSaveSome").then(function(){ const obj = new Parse.Object("SomeRandomObject"); return obj.save(); }).then(function() { var promise = new Parse.Promise(); - // Wait a bit here as it's an after save - setTimeout(function(){ + // Wait a bit here as it's an after save + setTimeout(() => { expect(triggerCount).toBe(1); - var q = new Parse.Query("AnotherObject"); - q.get(newObjectId).then(function(r){ - promise.resolve(r); - }); - }, 300) + new Parse.Query("AnotherObject") + .get(newObjectId) + .then((r) => promise.resolve(r)); + }, 500); return promise; }).then(function(res){ expect(res.get("foo")).toEqual("bar"); diff --git a/spec/ParseInstallation.spec.js b/spec/ParseInstallation.spec.js index a34e6d676b..b92c2adb71 100644 --- a/spec/ParseInstallation.spec.js +++ b/spec/ParseInstallation.spec.js @@ -12,6 +12,10 @@ let config; let database; const defaultColumns = require('../src/Controllers/SchemaController').defaultColumns; +const delay = function delay(delay) { + return new Promise(resolve => setTimeout(resolve, delay)); +} + const installationSchema = { fields: Object.assign({}, defaultColumns._Default, defaultColumns._Installation) }; describe('Installations', () => { @@ -542,12 +546,14 @@ describe('Installations', () => { }; return rest.create(config, auth.nobody(config), '_Installation', input); }) + .then(() => delay(100)) .then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId1}, {})) .then((results) => { expect(results.length).toEqual(1); firstObject = results[0]; - return database.adapter.find('_Installation', installationSchema, {installationId: installId2}, {}); }) + .then(() => delay(100)) + .then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId2}, {})) .then(results => { expect(results.length).toEqual(1); secondObject = results[0]; @@ -558,6 +564,7 @@ describe('Installations', () => { }; return rest.update(config, auth.nobody(config), '_Installation', secondObject.objectId, input); }) + .then(() => delay(100)) .then(() => database.adapter.find('_Installation', installationSchema, {objectId: firstObject.objectId}, {})) .then(results => { // The first object should have been deleted