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(fr): handle 0 throughput in timespan #13323

Merged
merged 8 commits into from
Nov 11, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class UnusedBytes extends Audit {
*/
static computeWastedMsWithThroughput(wastedBytes, simulator) {
const bitsPerSecond = simulator.getOptions().throughput;
// https://github.com/GoogleChrome/lighthouse/pull/13323#issuecomment-962031709
if (bitsPerSecond === 0) return 0;
adamraine marked this conversation as resolved.
Show resolved Hide resolved
const wastedBits = wastedBytes * 8;
const wastedMs = wastedBits / bitsPerSecond * 1000;
return wastedMs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,33 @@ describe('Byte efficiency base audit', () => {
score: 1,
});
});

it('should handle 0 download throughput in timespan', async () => {
class MockAudit extends ByteEfficiencyAudit {
static audit_(artifacts, records) {
return {
items: records.map(record => ({url: record.url, wastedBytes: record.transferSize * 0.5})),
headings: [],
};
}
}

const artifacts = {
GatherContext: {gatherMode: 'timespan'},
traces: {defaultPass: trace},
devtoolsLogs: {defaultPass: devtoolsLog},
};
const computedCache = new Map();

const modestThrottling = {
rttMs: 150,
requestLatencyMs: 150,
throughputKbps: 1000,
cpuSlowdownMultiplier: 2,
downloadThroughputKbps: 0,
};
const settings = {throttlingMethod: 'devtools', throttling: modestThrottling};
const result = await MockAudit.audit(artifacts, {settings, computedCache});
expect(result.details.overallSavingsMs).toBeCloseTo(0);
});
});