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

tests: add organic TTI savings case to byte efficieny audit #12418

Merged
merged 1 commit into from
Apr 28, 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const LoadSimulator = require('../../../computed/load-simulator.js');

const trace = require('../../fixtures/traces/progressive-app-m60.json');
const devtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json');
const traceM78 = require('../../fixtures/traces/lcp-m78.json');
const devtoolsLogM78 = require('../../fixtures/traces/lcp-m78.devtools.log.json');
const assert = require('assert').strict;

/* eslint-env jest */
Expand Down Expand Up @@ -230,16 +232,16 @@ describe('Byte efficiency base audit', () => {
let result = await MockAudit.audit(artifacts, {settings, computedCache});
// expect modest savings
expect(result.numericValue).toBeLessThan(5000);
expect(result.numericValue).toMatchSnapshot();
expect(result.numericValue).toMatchInlineSnapshot(`960`);

settings = {throttlingMethod: 'simulate', throttling: ultraSlowThrottling};
result = await MockAudit.audit(artifacts, {settings, computedCache});
// expect lots of savings
expect(result.numericValue).not.toBeLessThan(5000);
expect(result.numericValue).toMatchSnapshot();
expect(result.numericValue).toMatchInlineSnapshot(`21500`);
});

it('should allow overriding of computeWasteWithTTIGraph', async () => {
it('should compute TTI savings differently from load savings', async () => {
class MockAudit extends ByteEfficiencyAudit {
static audit_(artifacts, records) {
return {
Expand All @@ -249,15 +251,44 @@ describe('Byte efficiency base audit', () => {
}
}

class MockJustTTIAudit extends MockAudit {
class MockTtiAudit extends MockAudit {
static computeWasteWithTTIGraph(results, graph, simulator) {
// TODO: Pass in a graph that organically has a lower TTI result rather than forcing it
// to be scaled down.
return 0.9 * ByteEfficiencyAudit.computeWasteWithTTIGraph(results, graph, simulator,
return ByteEfficiencyAudit.computeWasteWithTTIGraph(results, graph, simulator,
{includeLoad: false});
}
}

const artifacts = {
traces: {defaultPass: traceM78},
devtoolsLogs: {defaultPass: devtoolsLogM78},
};
const computedCache = new Map();

const modestThrottling = {rttMs: 150, throughputKbps: 1000, cpuSlowdownMultiplier: 2};
const settings = {throttlingMethod: 'simulate', throttling: modestThrottling};
const result = await MockAudit.audit(artifacts, {settings, computedCache});
const resultTti = await MockTtiAudit.audit(artifacts, {settings, computedCache});
expect(resultTti.numericValue).toBeLessThan(result.numericValue);
expect(result.numericValue).toMatchInlineSnapshot(`2120`);
expect(resultTti.numericValue).toMatchInlineSnapshot(`150`);
});

it('should allow overriding of computeWasteWithTTIGraph', async () => {
class MockAudit extends ByteEfficiencyAudit {
static audit_(artifacts, records) {
return {
items: records.map(record => ({url: record.url, wastedBytes: record.transferSize * 0.5})),
headings: [],
};
}
}

class MockOverrideAudit extends MockAudit {
static computeWasteWithTTIGraph(results, graph, simulator) {
return 0.5 * ByteEfficiencyAudit.computeWasteWithTTIGraph(results, graph, simulator);
}
}

const artifacts = {
traces: {defaultPass: trace},
devtoolsLogs: {defaultPass: devtoolsLog},
Expand All @@ -267,9 +298,7 @@ describe('Byte efficiency base audit', () => {
const modestThrottling = {rttMs: 150, throughputKbps: 1000, cpuSlowdownMultiplier: 2};
const settings = {throttlingMethod: 'simulate', throttling: modestThrottling};
const result = await MockAudit.audit(artifacts, {settings, computedCache});
const resultTti = await MockJustTTIAudit.audit(artifacts, {settings, computedCache});
// expect less savings with just TTI
expect(resultTti.numericValue).toBeLessThan(result.numericValue);
expect({default: result.numericValue, justTTI: resultTti.numericValue}).toMatchSnapshot();
const resultOverride = await MockOverrideAudit.audit(artifacts, {settings, computedCache});
expect(resultOverride.numericValue).toEqual(result.numericValue * 0.5);
});
});