diff --git a/packages/-ember-data/tests/integration/store-test.js b/packages/-ember-data/tests/integration/store-test.js index f244bcd2ee8..ab6911f7319 100644 --- a/packages/-ember-data/tests/integration/store-test.js +++ b/packages/-ember-data/tests/integration/store-test.js @@ -154,7 +154,6 @@ module('integration/store - destroy', function (hooks) { this.owner.register('adapter:application', TestAdapter); - store.shouldTrackAsyncRequests = true; store.push = function () { assert('The test should have destroyed the store by now', store.isDestroyed); @@ -291,7 +290,6 @@ module('integration/store - findRecord', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); store = this.owner.lookup('service:store'); - store.shouldTrackAsyncRequests = true; }); test('store#findRecord fetches record from server when cached record is not present', async function (assert) { diff --git a/packages/-ember-data/tests/unit/store/async-leak-test.js b/packages/-ember-data/tests/unit/store/async-leak-test.js index e8f826da5a3..3f181f93231 100644 --- a/packages/-ember-data/tests/unit/store/async-leak-test.js +++ b/packages/-ember-data/tests/unit/store/async-leak-test.js @@ -34,7 +34,6 @@ module('unit/store async-waiter and leak detection', function (hooks) { }) ); store = owner.lookup('service:store'); - store.shouldTrackAsyncRequests = true; }); test('the waiter properly waits for pending requests', async function (assert) { @@ -71,44 +70,6 @@ module('unit/store async-waiter and leak detection', function (hooks) { assert.true(waiter(), 'We return true to end waiting when no requests are pending'); }); - test('waiter can be turned off', async function (assert) { - let findRecordWasInvoked; - let findRecordWasInvokedPromise = new Promise((resolveStep) => { - findRecordWasInvoked = resolveStep; - }); - this.owner.register( - 'adapter:application', - JSONAPIAdapter.extend({ - findRecord() { - return new Promise((resolve) => { - findRecordWasInvoked(); - - setTimeout(() => { - resolve({ data: { type: 'person', id: '1' } }); - }, 20); // intentionally longer than the 10ms polling interval of `wait()` - }); - }, - }) - ); - - // turn off the waiter - store.shouldTrackAsyncRequests = false; - - let request = store.findRecord('person', '1'); - let waiter = store.__asyncWaiter; - - assert.true(waiter(), 'We return true when no requests have been initiated yet (pending queue flush is async)'); - - await findRecordWasInvokedPromise; - - assert.strictEqual(store._trackedAsyncRequests.length, 1, 'We return true even though a request is pending'); - assert.true(waiter(), 'We return true even though a request is pending'); - - await request; - - assert.true(waiter(), 'We return true to end waiting when no requests are pending'); - }); - test('waiter works even when the adapter rejects', async function (assert) { assert.expect(4); let findRecordWasInvoked; @@ -211,57 +172,6 @@ module('unit/store async-waiter and leak detection', function (hooks) { } }); - test('when the store is torn down too early, but the waiter behavior is turned off, we emit a warning', async function (assert) { - let next; - let stepPromise = new Promise((resolveStep) => { - next = resolveStep; - }); - this.owner.register( - 'adapter:application', - JSONAPIAdapter.extend({ - findRecord() { - next(); - stepPromise = new Promise((resolveStep) => { - next = resolveStep; - }).then(() => { - return { data: { type: 'person', id: '1' } }; - }); - return stepPromise; - }, - }) - ); - - // turn off the waiter - store.shouldTrackAsyncRequests = false; - - store.findRecord('person', '1'); - let waiter = store.__asyncWaiter; - - assert.strictEqual(store._trackedAsyncRequests.length, 0, 'We have no requests yet'); - assert.true(waiter(), 'We return true when no requests have been initiated yet (pending queue flush is async)'); - - await stepPromise; - - assert.strictEqual(store._trackedAsyncRequests.length, 1, 'We have a pending request'); - assert.true(waiter(), 'We return true because the waiter is turned off'); - assert.expectWarning(() => { - run(() => { - store.destroy(); - }); - }, /Async Request leaks detected/); - - assert.true(waiter(), 'We return true because the waiter is turned off'); - - // make the waiter complete - run(() => next()); - assert.strictEqual(store._trackedAsyncRequests.length, 0, 'Our pending request is cleaned up'); - assert.true(waiter(), 'We return true because the waiter is cleared'); - - if (DEPRECATE_RSVP_PROMISE) { - assert.expectDeprecation({ id: 'ember-data:rsvp-unresolved-async', count: 1 }); - } - }); - test('when configured, pending requests have useful stack traces', async function (assert) { let stepResolve; let stepPromise = new Promise((resolveStep) => { diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 50f4da52ab0..7c4a1b7a1d3 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -197,7 +197,6 @@ abstract class CoreStore extends Service { // DEBUG-only properties declare _trackedAsyncRequests: AsyncTrackingToken[]; - declare shouldTrackAsyncRequests: boolean; declare generateStackTracesForTrackedRequests: boolean; declare _trackAsyncRequestStart: (str: string) => void; declare _trackAsyncRequestEnd: (token: AsyncTrackingToken) => void; @@ -276,9 +275,6 @@ abstract class CoreStore extends Service { this.identifierCache = new IdentifierCache(); if (DEBUG) { - if (this.shouldTrackAsyncRequests === undefined) { - this.shouldTrackAsyncRequests = false; - } if (this.generateStackTracesForTrackedRequests === undefined) { this.generateStackTracesForTrackedRequests = false; } @@ -317,11 +313,8 @@ abstract class CoreStore extends Service { }; this.__asyncWaiter = () => { - let shouldTrack = this.shouldTrackAsyncRequests; let tracked = this._trackedAsyncRequests; - let isSettled = tracked.length === 0; - - return shouldTrack !== true || isSettled; + return tracked.length === 0; }; registerWaiter(this.__asyncWaiter); @@ -3185,26 +3178,14 @@ abstract class CoreStore extends Service { if (DEBUG) { unregisterWaiter(this.__asyncWaiter); - let shouldTrack = this.shouldTrackAsyncRequests; let tracked = this._trackedAsyncRequests; let isSettled = tracked.length === 0; if (!isSettled) { - if (shouldTrack) { - throw new Error( - 'Async Request leaks detected. Add a breakpoint here and set `store.generateStackTracesForTrackedRequests = true;`to inspect traces for leak origins:\n\t - ' + - tracked.map((o) => o.label).join('\n\t - ') - ); - } else { - warn( - 'Async Request leaks detected. Add a breakpoint here and set `store.generateStackTracesForTrackedRequests = true;`to inspect traces for leak origins:\n\t - ' + - tracked.map((o) => o.label).join('\n\t - '), - false, - { - id: 'ds.async.leak.detected', - } - ); - } + throw new Error( + 'Async Request leaks detected. Add a breakpoint here and set `store.generateStackTracesForTrackedRequests = true;`to inspect traces for leak origins:\n\t - ' + + tracked.map((o) => o.label).join('\n\t - ') + ); } } }