Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] upgrade rsvp + backburner #11903

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"qunit-phantom-runner": "jonkemp/qunit-phantomjs-runner#1.2.0"
},
"devDependencies": {
"backburner": "https://github.com/ebryn/backburner.js.git#4a0105a4a0bc4cf73bdf3e554aea14f3f438876c",
"rsvp": "https://github.com/tildeio/rsvp.js.git#3.0.14",
"backburner": "https://github.com/ebryn/backburner.js.git#ea82b6d703a7b65b4c4c65671843edb8d67f2a6c",
"rsvp": "https://github.com/tildeio/rsvp.js.git#3.0.20",
"router.js": "https://github.com/tildeio/router.js.git#ed45bc5c5e055af0ab875ef2c52feda792ee23e4",
"dag-map": "https://github.com/krisselden/dag-map.git#e307363256fe918f426e5a646cb5f5062d3245be",
"ember-dev": "https://github.com/emberjs/ember-dev.git#a064f0cd2f4c225ffd023b63d4cb31a79db04aaf"
Expand Down
9 changes: 6 additions & 3 deletions packages/ember-runtime/lib/ext/rsvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export function onerrorDefault(e) {
Test.adapter.exception(error);
Logger.error(error.stack);
} else {
Ember.run.schedule(Ember.run.queues[Ember.run.queues.length-1], function() {
throw error;
});
throw error;
}
} else if (Ember.onerror) {
Ember.onerror(error);
Expand All @@ -73,6 +71,11 @@ export function onerrorDefault(e) {
}
}

export function after (cb) {
Ember.run.schedule(Ember.run.queues[Ember.run.queues.length - 1], cb);
}

RSVP.on('error', onerrorDefault);
RSVP.configure('after', after);

export default RSVP;
126 changes: 125 additions & 1 deletion packages/ember-runtime/tests/ext/rsvp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ QUnit.test('rejections like jqXHR which have errorThrown property work', functio
}
});


QUnit.test('rejections where the errorThrown is a string should wrap the sting in an error object', function() {
expect(2);

Expand All @@ -167,3 +166,128 @@ QUnit.test('rejections where the errorThrown is a string should wrap the sting i
Ember.testing = wasEmberTesting;
}
});

var wasTesting;
var reason = 'i failed';
QUnit.module('Ember.test: rejection assertions', {
before() {
wasTesting = Ember.testing;
Ember.testing = true;
},
after() {
Ember.testing = wasTesting;
}
});

function ajax(something) {
return RSVP.Promise(function(resolve) {
QUnit.stop();
setTimeout(function() {
QUnit.start();
resolve();
}, 0); // fake true / foreign async
});
}

QUnit.test('unambigiously unhandled rejection', function() {
QUnit.throws(function() {
Ember.run(function() {
RSVP.Promise.reject(reason);
}); // something is funky, we should likely assert
}, reason);
});

QUnit.test('sync handled', function() {
Ember.run(function() {
RSVP.Promise.reject(reason).catch(function() { });
}); // handled, we shouldn't need to assert.
ok(true, 'reached end of test');
});

QUnit.test('handled within the same micro-task (via Ember.RVP.Promise)', function() {
Ember.run(function() {
var rejection = RSVP.Promise.reject(reason);
RSVP.Promise.resolve(1).then(() => rejection.catch(function() { }));
}); // handled, we shouldn't need to assert.
ok(true, 'reached end of test');
});

QUnit.test('handled within the same micro-task (via direct run-loop)', function() {
Ember.run(function() {
var rejection = RSVP.Promise.reject(reason);

Ember.run.schedule('afterRender', () => rejection.catch(function() { }));
}); // handled, we shouldn't need to assert.
ok(true, 'reached end of test');
});

QUnit.test('handled in the next microTask queue flush (Ember.run.next)', function() {
expect(2);

QUnit.throws(function() {
Ember.run(function() {
var rejection = RSVP.Promise.reject(reason);

QUnit.stop();
Ember.run.next(() => {
QUnit.start();
rejection.catch(function() { });
ok(true, 'reached end of test');
});
});
}, reason);

// a promise rejection survived a full flush of the run-loop without being handled
// this is very likely an issue.
});

QUnit.test('handled in the same microTask Queue flush do to data locality', function() {
// an ambiguous scenario, this may or may not assert
// it depends on the locality of `user#1`
var store = {
find() {
return Promise.resolve(1);
}
};

Ember.run(function() {
var rejection = RSVP.Promise.reject(reason);

store.find('user', 1).then(() => rejection.catch(function() { }));
});

ok(true, 'reached end of test');
});

QUnit.test('handled in a different microTask Queue flush do to data locality', function() {
// an ambiguous scenario, this may or may not assert
// it depends on the locality of `user#1`
var store = {
find() {
return ajax();
}
};

QUnit.throws(function() {
Ember.run(function() {
var rejection = RSVP.Promise.reject(reason);

store.find('user', 1).then(() => {
rejection.catch(function() { });
ok(true, 'reached end of test');
});
});
}, reason);
});

QUnit.test('handled in the next microTask queue flush (ajax example)', function() {
QUnit.throws(function() {
Ember.run(function() {
var rejection = RSVP.Promise.reject(reason);
ajax('/something/').then(() => {
rejection.catch(function() { });
ok(true, 'reached end of test');
});
});
}, reason);
});