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

core(lantern): do not create self-dependencies via timers #10280

Merged
merged 1 commit into from
Jan 30, 2020
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
2 changes: 1 addition & 1 deletion lighthouse-core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class PageDependencyGraph {
case 'TimerFire': {
// @ts-ignore - 'TimerFire' event means timerId exists.
const installer = timers.get(evt.args.data.timerId);
if (!installer) break;
if (!installer || installer.endTime > node.startTime) break;
installer.addDependent(node);
break;
}
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/lib/dependency-graph/base-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class BaseNode {
* @param {Node} node
*/
addDependency(node) {
// @ts-ignore - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.
if (node === this) throw new Error('Cannot add dependency on itself');

if (this._dependencies.includes(node)) {
return;
}
Expand Down
27 changes: 25 additions & 2 deletions lighthouse-core/test/computed/page-dependency-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ describe('PageDependencyGraph computed artifact:', () => {
]);

addTaskEvents(600, 150, [
// CPU 1.4 should depend on Network 4 even though it ends at 410ms
// CPU 1.6 should depend on Network 4 even though it ends at 410ms
{name: 'InvalidateLayout', data: {stackTrace: [{url: '4'}]}},
// Network 5 should not depend on CPU 1.4 because it started before CPU 1.4
// Network 5 should not depend on CPU 1.6 because it started before CPU 1.6
{name: 'ResourceSendRequest', data: {requestId: 5}},
]);

Expand All @@ -282,6 +282,29 @@ describe('PageDependencyGraph computed artifact:', () => {
assert.deepEqual(getDependencyIds(nodes[6]), [4]);
});

it('should not install timer dependency on itself', () => {
const request1 = createRequest(1, '1', 0);
const networkRecords = [request1];

addTaskEvents(200, 200, [
// CPU 1.2 should depend on Network 1
{name: 'EvaluateScript', data: {url: '1'}},
// CPU 1.2 will install and fire it's own timer, but should not depend on itself
{name: 'TimerInstall', data: {timerId: 'timer1'}},
{name: 'TimerFire', data: {timerId: 'timer1'}},
]);

const graph = PageDependencyGraph.createGraph(traceOfTab, networkRecords);
const nodes = [];
graph.traverse(node => nodes.push(node));

const getDependencyIds = node => node.getDependencies().map(node => node.id);

assert.equal(nodes.length, 2);
assert.deepEqual(getDependencyIds(nodes[0]), []);
assert.deepEqual(getDependencyIds(nodes[1]), [1]);
});

it('should prune short tasks', () => {
const request0 = createRequest(0, '0', 0);
const request1 = createRequest(1, '1', 100, null, NetworkRequest.TYPES.Script);
Expand Down
5 changes: 5 additions & 0 deletions lighthouse-core/test/lib/dependency-graph/base-node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ describe('DependencyGraph/Node', () => {
assert.deepEqual(nodeA.getDependencies(), [nodeB]);
assert.deepEqual(nodeB.getDependents(), [nodeA]);
});

it('throw when trying to add a dependency on itself', () => {
const nodeA = new BaseNode(1);
expect(() => nodeA.addDependency(nodeA)).toThrow();
});
});

describe('.getRootNode', () => {
Expand Down