Skip to content

Commit 4979503

Browse files
author
Arthur Cinader
authored
Two tests that fail often. Give em a little more time. (#3453)
1 parent e32a37c commit 4979503

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

spec/CloudCodeLogger.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ describe("Cloud Code Logger", () => {
156156
.save()
157157
.then(
158158
() => done.fail('this is not supposed to succeed'),
159-
() => logController.getLogs({ from: Date.now() - 500, size: 1000 })
159+
() => new Promise(resolve => setTimeout(resolve, 100))
160160
)
161+
.then(() => logController.getLogs({ from: Date.now() - 500, size: 1000 }))
161162
.then(logs => {
162163
const log = logs[1]; // 0 is the 'uh oh!' from rejection...
163164
expect(log.level).toEqual('error');

spec/ParseHooks.spec.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ describe('Hooks', () => {
143143
});
144144

145145
it("should fail trying to create two times the same function", (done) => {
146-
Parse.Hooks.createFunction("my_new_function", "http://url.com").then(() => {
146+
Parse.Hooks.createFunction("my_new_function", "http://url.com")
147+
.then(() => new Promise(resolve => setTimeout(resolve, 100)))
148+
.then(() => {
147149
return Parse.Hooks.createFunction("my_new_function", "http://url.com")
148150
}, () => {
149151
fail("should create a new function");
@@ -421,8 +423,8 @@ describe('Hooks', () => {
421423
// But this should override the key upon return
422424
res.json({success: object});
423425
});
424-
// The function is delete as the DB is dropped between calls
425-
Parse.Hooks.createTrigger("SomeRandomObject", "beforeSave" ,hookServerURL + "/BeforeSaveSome").then(function(){
426+
// The function is deleted as the DB is dropped between calls
427+
Parse.Hooks.createTrigger("SomeRandomObject", "beforeSave", hookServerURL + "/BeforeSaveSome").then(function () {
426428
const obj = new Parse.Object("SomeRandomObject");
427429
return obj.save();
428430
}).then(function(res) {
@@ -444,7 +446,7 @@ describe('Hooks', () => {
444446
object.set('hello', "world");
445447
res.json({success: object});
446448
});
447-
Parse.Hooks.createTrigger("SomeRandomObject2", "beforeSave" ,hookServerURL + "/BeforeSaveSome2").then(function(){
449+
Parse.Hooks.createTrigger("SomeRandomObject2", "beforeSave", hookServerURL + "/BeforeSaveSome2").then(function(){
448450
const obj = new Parse.Object("SomeRandomObject2");
449451
return obj.save();
450452
}).then(function(res) {
@@ -470,20 +472,19 @@ describe('Hooks', () => {
470472
res.json({success: {}});
471473
})
472474
});
473-
// The function is delete as the DB is dropped between calls
474-
Parse.Hooks.createTrigger("SomeRandomObject", "afterSave" ,hookServerURL + "/AfterSaveSome").then(function(){
475+
// The function is deleted as the DB is dropped between calls
476+
Parse.Hooks.createTrigger("SomeRandomObject", "afterSave", hookServerURL + "/AfterSaveSome").then(function(){
475477
const obj = new Parse.Object("SomeRandomObject");
476478
return obj.save();
477479
}).then(function() {
478480
var promise = new Parse.Promise();
479-
// Wait a bit here as it's an after save
480-
setTimeout(function(){
481+
// Wait a bit here as it's an after save
482+
setTimeout(() => {
481483
expect(triggerCount).toBe(1);
482-
var q = new Parse.Query("AnotherObject");
483-
q.get(newObjectId).then(function(r){
484-
promise.resolve(r);
485-
});
486-
}, 300)
484+
new Parse.Query("AnotherObject")
485+
.get(newObjectId)
486+
.then((r) => promise.resolve(r));
487+
}, 500);
487488
return promise;
488489
}).then(function(res){
489490
expect(res.get("foo")).toEqual("bar");

spec/ParseInstallation.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ let config;
1212
let database;
1313
const defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;
1414

15+
const delay = function delay(delay) {
16+
return new Promise(resolve => setTimeout(resolve, delay));
17+
}
18+
1519
const installationSchema = { fields: Object.assign({}, defaultColumns._Default, defaultColumns._Installation) };
1620

1721
describe('Installations', () => {
@@ -542,12 +546,14 @@ describe('Installations', () => {
542546
};
543547
return rest.create(config, auth.nobody(config), '_Installation', input);
544548
})
549+
.then(() => delay(100))
545550
.then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId1}, {}))
546551
.then((results) => {
547552
expect(results.length).toEqual(1);
548553
firstObject = results[0];
549-
return database.adapter.find('_Installation', installationSchema, {installationId: installId2}, {});
550554
})
555+
.then(() => delay(100))
556+
.then(() => database.adapter.find('_Installation', installationSchema, {installationId: installId2}, {}))
551557
.then(results => {
552558
expect(results.length).toEqual(1);
553559
secondObject = results[0];
@@ -558,6 +564,7 @@ describe('Installations', () => {
558564
};
559565
return rest.update(config, auth.nobody(config), '_Installation', secondObject.objectId, input);
560566
})
567+
.then(() => delay(100))
561568
.then(() => database.adapter.find('_Installation', installationSchema, {objectId: firstObject.objectId}, {}))
562569
.then(results => {
563570
// The first object should have been deleted

0 commit comments

Comments
 (0)