Skip to content

Commit

Permalink
core(fr): handle 0 throughput in timespan (#13323)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Clark <cjamcl@google.com>
  • Loading branch information
adamraine and connorjclark authored Nov 11, 2021
1 parent dbbbe64 commit 9d293da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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;
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);
});
});

0 comments on commit 9d293da

Please sign in to comment.