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

WIP: Keep a record of stale owners to help better debug poor test isolation #20513

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 15 additions & 2 deletions packages/@ember/-internals/container/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
FullName,
} from '@ember/-internals/owner';
import { setOwner } from '@ember/-internals/owner';
import { dictionary } from '@ember/-internals/utils';
import { dictionary, guidFor } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import type { DebugRegistry } from './registry';
Expand Down Expand Up @@ -53,7 +53,7 @@
export interface ContainerOptions {
owner?: InternalOwner;
cache?: { [key: string]: object };
factoryManagerCache?: { [key: string]: InternalFactoryManager<any, any> };

Check warning on line 56 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type

Check warning on line 56 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type
validationCache?: { [key: string]: boolean };
}

Expand Down Expand Up @@ -152,7 +152,20 @@
options?: RegisterOptions
): InternalFactory<object> | object | undefined {
if (this.isDestroyed) {
throw new Error(`Cannot call \`.lookup('${fullName}')\` after the owner has been destroyed`);
if (macroCondition(isTesting())) {

Check failure on line 155 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Cannot find name 'macroCondition'.

Check failure on line 155 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Cannot find name 'isTesting'.

Check failure on line 155 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Cannot find name 'macroCondition'.

Check failure on line 155 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Cannot find name 'isTesting'.
let guid = guidFor(this.owner);
// SAFETY: cast is for accessing private data stored globally
let testInfo = (globalThis as any)['__OWNER_MAP__']?.get(guid);

Check warning on line 158 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type

throw new Error(
`Cannot call \`.lookup('${fullName}')\` after the owner has been destroyed. ` +
`owner is ${guid} (test ${testInfo?.testId} ${testInfo?.name})`
);
} else {
throw new Error(
`Cannot call \`.lookup('${fullName}')\` after the owner has been destroyed`
);
}
}
assert('fullName must be a proper full name', this.registry.isValidFullName(fullName));
return lookup(this, this.registry.normalize(fullName), options);
Expand Down Expand Up @@ -201,7 +214,7 @@
*/
ownerInjection() {
let injection = {};
setOwner(injection, this.owner!);

Check warning on line 217 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Forbidden non-null assertion
return injection;
}

Expand Down Expand Up @@ -230,7 +243,7 @@
}

if (DEBUG) {
Container._leakTracking = leakTracking!;

Check warning on line 246 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Forbidden non-null assertion
}

/*
Expand Down Expand Up @@ -261,7 +274,7 @@
},
};

return new Proxy(proxiedManager, validator as any) as any;

Check warning on line 277 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type

Check warning on line 277 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type
}

function isSingleton(container: Container, fullName: FullName) {
Expand Down Expand Up @@ -393,8 +406,8 @@
// if this lookup happened _during_ destruction (emits a deprecation, but
// is still possible) ensure that it gets destroyed
if (container.isDestroying) {
if (typeof (instance as any).destroy === 'function') {

Check warning on line 409 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type
(instance as any).destroy();

Check warning on line 410 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type
}
}

Expand Down Expand Up @@ -425,7 +438,7 @@
let value = cache[key];
assert('has cached value', value);

if ((value as any).destroy) {

Check warning on line 441 in packages/@ember/-internals/container/lib/container.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected any. Specify a different type
(value as any).destroy();
}
}
Expand Down
29 changes: 24 additions & 5 deletions packages/@ember/-internals/metal/lib/property_set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { lookupDescriptor, setWithMandatorySetter, toString } from '@ember/-internals/utils';
import { getOwner } from '@ember/-internals/owner';
import {
guidFor,
lookupDescriptor,
setWithMandatorySetter,
toString,
} from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { COMPUTED_SETTERS } from './decorator';
Expand Down Expand Up @@ -55,10 +61,23 @@
);

if ((obj as ExtendedObject).isDestroyed) {
assert(
`calling set on destroyed object: ${toString(obj)}.${keyName} = ${toString(value)}`,
tolerant
);
if (macroCondition(isTesting())) {

Check failure on line 64 in packages/@ember/-internals/metal/lib/property_set.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Cannot find name 'macroCondition'.

Check failure on line 64 in packages/@ember/-internals/metal/lib/property_set.ts

View workflow job for this annotation

GitHub Actions / Debug and Prebuilt (All Tests by Package + Canary Features)

Cannot find name 'isTesting'.

Check failure on line 64 in packages/@ember/-internals/metal/lib/property_set.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Cannot find name 'macroCondition'.

Check failure on line 64 in packages/@ember/-internals/metal/lib/property_set.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Cannot find name 'isTesting'.
let guid = guidFor(getOwner(obj));

// SAFETY: cast is for accessing private data stored globally
let testInfo = (globalThis as any)['__OWNER_MAP__']?.get(guid);
assert(
`calling set on destroyed object: ${toString(obj)}.${keyName} = ${toString(value)} ` +
`owner is ${guid} (test ${testInfo?.testId} ${testInfo?.name})`,
tolerant
);
} else {
assert(
`calling set on destroyed object: ${toString(obj)}.${keyName} = ${toString(value)}`,
tolerant
);
}

return value;
}

Expand Down
Loading