Skip to content

Commit 02a8f86

Browse files
committed
Merge pull request #11903 from stefanpenner/upgrade-rsvp-and-backburner
[BUGFIX release] upgrade rsvp + backburner
2 parents 6e00835 + 260a81f commit 02a8f86

File tree

3 files changed

+133
-6
lines changed

3 files changed

+133
-6
lines changed

bower.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"qunit-phantom-runner": "jonkemp/qunit-phantomjs-runner#1.2.0"
1111
},
1212
"devDependencies": {
13-
"backburner": "https://github.com/ebryn/backburner.js.git#4a0105a4a0bc4cf73bdf3e554aea14f3f438876c",
14-
"rsvp": "https://github.com/tildeio/rsvp.js.git#3.0.14",
13+
"backburner": "https://github.com/ebryn/backburner.js.git#ea82b6d703a7b65b4c4c65671843edb8d67f2a6c",
14+
"rsvp": "https://github.com/tildeio/rsvp.js.git#3.0.20",
1515
"router.js": "https://github.com/tildeio/router.js.git#ed45bc5c5e055af0ab875ef2c52feda792ee23e4",
1616
"dag-map": "https://github.com/krisselden/dag-map.git#e307363256fe918f426e5a646cb5f5062d3245be",
1717
"ember-dev": "https://github.com/emberjs/ember-dev.git#a064f0cd2f4c225ffd023b63d4cb31a79db04aaf"

packages/ember-runtime/lib/ext/rsvp.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ export function onerrorDefault(e) {
6161
Test.adapter.exception(error);
6262
Logger.error(error.stack);
6363
} else {
64-
Ember.run.schedule(Ember.run.queues[Ember.run.queues.length-1], function() {
65-
throw error;
66-
});
64+
throw error;
6765
}
6866
} else if (Ember.onerror) {
6967
Ember.onerror(error);
@@ -73,6 +71,11 @@ export function onerrorDefault(e) {
7371
}
7472
}
7573

74+
export function after (cb) {
75+
Ember.run.schedule(Ember.run.queues[Ember.run.queues.length - 1], cb);
76+
}
77+
7678
RSVP.on('error', onerrorDefault);
79+
RSVP.configure('after', after);
7780

7881
export default RSVP;

packages/ember-runtime/tests/ext/rsvp_test.js

+125-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ QUnit.test('rejections like jqXHR which have errorThrown property work', functio
142142
}
143143
});
144144

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

@@ -167,3 +166,128 @@ QUnit.test('rejections where the errorThrown is a string should wrap the sting i
167166
Ember.testing = wasEmberTesting;
168167
}
169168
});
169+
170+
var wasTesting;
171+
var reason = 'i failed';
172+
QUnit.module('Ember.test: rejection assertions', {
173+
before() {
174+
wasTesting = Ember.testing;
175+
Ember.testing = true;
176+
},
177+
after() {
178+
Ember.testing = wasTesting;
179+
}
180+
});
181+
182+
function ajax(something) {
183+
return RSVP.Promise(function(resolve) {
184+
QUnit.stop();
185+
setTimeout(function() {
186+
QUnit.start();
187+
resolve();
188+
}, 0); // fake true / foreign async
189+
});
190+
}
191+
192+
QUnit.test('unambigiously unhandled rejection', function() {
193+
QUnit.throws(function() {
194+
Ember.run(function() {
195+
RSVP.Promise.reject(reason);
196+
}); // something is funky, we should likely assert
197+
}, reason);
198+
});
199+
200+
QUnit.test('sync handled', function() {
201+
Ember.run(function() {
202+
RSVP.Promise.reject(reason).catch(function() { });
203+
}); // handled, we shouldn't need to assert.
204+
ok(true, 'reached end of test');
205+
});
206+
207+
QUnit.test('handled within the same micro-task (via Ember.RVP.Promise)', function() {
208+
Ember.run(function() {
209+
var rejection = RSVP.Promise.reject(reason);
210+
RSVP.Promise.resolve(1).then(() => rejection.catch(function() { }));
211+
}); // handled, we shouldn't need to assert.
212+
ok(true, 'reached end of test');
213+
});
214+
215+
QUnit.test('handled within the same micro-task (via direct run-loop)', function() {
216+
Ember.run(function() {
217+
var rejection = RSVP.Promise.reject(reason);
218+
219+
Ember.run.schedule('afterRender', () => rejection.catch(function() { }));
220+
}); // handled, we shouldn't need to assert.
221+
ok(true, 'reached end of test');
222+
});
223+
224+
QUnit.test('handled in the next microTask queue flush (Ember.run.next)', function() {
225+
expect(2);
226+
227+
QUnit.throws(function() {
228+
Ember.run(function() {
229+
var rejection = RSVP.Promise.reject(reason);
230+
231+
QUnit.stop();
232+
Ember.run.next(() => {
233+
QUnit.start();
234+
rejection.catch(function() { });
235+
ok(true, 'reached end of test');
236+
});
237+
});
238+
}, reason);
239+
240+
// a promise rejection survived a full flush of the run-loop without being handled
241+
// this is very likely an issue.
242+
});
243+
244+
QUnit.test('handled in the same microTask Queue flush do to data locality', function() {
245+
// an ambiguous scenario, this may or may not assert
246+
// it depends on the locality of `user#1`
247+
var store = {
248+
find() {
249+
return Promise.resolve(1);
250+
}
251+
};
252+
253+
Ember.run(function() {
254+
var rejection = RSVP.Promise.reject(reason);
255+
256+
store.find('user', 1).then(() => rejection.catch(function() { }));
257+
});
258+
259+
ok(true, 'reached end of test');
260+
});
261+
262+
QUnit.test('handled in a different microTask Queue flush do to data locality', function() {
263+
// an ambiguous scenario, this may or may not assert
264+
// it depends on the locality of `user#1`
265+
var store = {
266+
find() {
267+
return ajax();
268+
}
269+
};
270+
271+
QUnit.throws(function() {
272+
Ember.run(function() {
273+
var rejection = RSVP.Promise.reject(reason);
274+
275+
store.find('user', 1).then(() => {
276+
rejection.catch(function() { });
277+
ok(true, 'reached end of test');
278+
});
279+
});
280+
}, reason);
281+
});
282+
283+
QUnit.test('handled in the next microTask queue flush (ajax example)', function() {
284+
QUnit.throws(function() {
285+
Ember.run(function() {
286+
var rejection = RSVP.Promise.reject(reason);
287+
ajax('/something/').then(() => {
288+
rejection.catch(function() { });
289+
ok(true, 'reached end of test');
290+
});
291+
});
292+
}, reason);
293+
});

0 commit comments

Comments
 (0)