Skip to content

Commit

Permalink
[BUGFIX] Await potentially async operations (#6441)
Browse files Browse the repository at this point in the history
Some operations in Ember Data flush using `run.join`. This will flush
_synchronously_ if no runloop or autorun currently exists, but will
join the existing runloop otherwise, making the scheduled task
effectively asynchronous.

With the tracked properties feature flag enabled, the way we've
scheduled autoruns has changed. A few Data tests were failing because
they were expecting an operation to flush synchronously, but it flushed
asynchronously due to an existing autorun. This PR adds appropriate
`await settled();` statements in these cases.
  • Loading branch information
Gaurav0 authored and runspired committed Sep 12, 2019
1 parent c89f4b3 commit 3b28438
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function(
);
});

test('When all records for a type are requested, records that are created on the client should be added to the record array.', assert => {
test('When all records for a type are requested, records that are created on the client should be added to the record array.', async assert => {
assert.expect(3);

let allRecords = store.peekAll('person');
Expand All @@ -154,6 +154,8 @@ module('integration/adapter/find-all - Finding All Records of a Type', function(

store.createRecord('person', { name: 'Carsten Nielsen' });

await settled();

assert.equal(get(allRecords, 'length'), 1, "the record array's length is 1");
assert.equal(
allRecords.objectAt(0).get('name'),
Expand Down
3 changes: 3 additions & 0 deletions packages/-ember-data/tests/integration/record-array-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,15 @@ module('unit/record-array - RecordArray', function(hooks) {
name: 'Scumbag Dale',
});

await settled();
assert.equal(get(recordArray, 'length'), 1, 'precond - record array already has the first created item');

store.createRecord('person', { name: 'p1' });
store.createRecord('person', { name: 'p2' });
store.createRecord('person', { name: 'p3' });

await settled();

assert.equal(get(recordArray, 'length'), 4, 'precond - record array has the created item');
assert.equal(recordArray.objectAt(0), scumbag, 'item at index 0 is record with id 1');

Expand Down

0 comments on commit 3b28438

Please sign in to comment.