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: use newer traces in network-analyzer-test.js #16043

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
46 changes: 25 additions & 21 deletions core/test/lib/lantern/simulator/network-analyzer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {NetworkRecords} from '../../../../computed/network-records.js';
import {readJson} from '../../../test-utils.js';
import {NetworkRequest} from '../../../../lib/network-request.js';

// TODO(15841): use new traces
const devtoolsLog = readJson('../../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
const devtoolsLog = readJson('../../../fixtures/artifacts/paul/devtoolslog.json', import.meta);
const devtoolsLogWithRedirect = readJson('../../../fixtures/artifacts/redirect/devtoolslog.json', import.meta);

describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
Expand Down Expand Up @@ -135,8 +134,8 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
return NetworkRecords.request(devtoolsLog, {computedCache: new Map()}).then(records => {
const result = NetworkAnalyzer.estimateIfConnectionWasReused(records);
const distinctConnections = Array.from(result.values()).filter(item => !item).length;
assert.equal(result.size, 66);
assert.equal(distinctConnections, 3);
assert.equal(result.size, 27);
assert.equal(distinctConnections, 9);
});
});
});
Expand Down Expand Up @@ -248,9 +247,9 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
it('should work on a real devtoolsLog', () => {
return NetworkRecords.request(devtoolsLog, {computedCache: new Map()}).then(records => {
const result = NetworkAnalyzer.estimateRTTByOrigin(records);
assertCloseEnough(result.get('https://pwa.rocks').min, 3);
assertCloseEnough(result.get('https://www.googletagmanager.com').min, 3);
assertCloseEnough(result.get('https://www.google-analytics.com').min, 4);
assertCloseEnough(result.get('https://www.paulirish.com').min, 10);
assertCloseEnough(result.get('https://www.googletagmanager.com').min, 17);
assertCloseEnough(result.get('https://www.google-analytics.com').min, 10);
});
});

Expand Down Expand Up @@ -313,9 +312,9 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
it('should work on a real devtoolsLog', () => {
return NetworkRecords.request(devtoolsLog, {computedCache: new Map()}).then(records => {
const result = NetworkAnalyzer.estimateServerResponseTimeByOrigin(records);
assertCloseEnough(result.get('https://pwa.rocks').avg, 162);
assertCloseEnough(result.get('https://www.googletagmanager.com').avg, 153);
assertCloseEnough(result.get('https://www.google-analytics.com').avg, 161);
assertCloseEnough(result.get('https://www.paulirish.com').avg, 35);
assertCloseEnough(result.get('https://www.googletagmanager.com').avg, 8);
assertCloseEnough(result.get('https://www.google-analytics.com').avg, 8);
});
});

Expand Down Expand Up @@ -442,14 +441,19 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
describe('#computeRTTAndServerResponseTime', () => {
it('should work', async () => {
const records = await NetworkRecords.request(devtoolsLog, {computedCache: new Map()});
const result = await NetworkAnalyzer.computeRTTAndServerResponseTime(records);
const result = NetworkAnalyzer.computeRTTAndServerResponseTime(records);

expect(Math.round(result.rtt)).toEqual(3);
expect(Math.round(result.rtt)).toEqual(2);
expect(result.additionalRttByOrigin).toMatchInlineSnapshot(`
Map {
"https://pwa.rocks" => 0.3960000176447025,
"https://www.googletagmanager.com" => 0,
"https://www.google-analytics.com" => 1.0450000117997007,
"https://www.paulirish.com" => 8.099999999999994,
"https://www.googletagmanager.com" => 15.530999999999992,
"https://fonts.googleapis.com" => 15.127000000000002,
"https://fonts.gstatic.com" => 0,
"https://www.google-analytics.com" => 8.235999999999997,
"https://paulirish.disqus.com" => 7.3119999999999985,
"https://firebaseinstallations.googleapis.com" => 6.473,
"https://firebaseremoteconfig.googleapis.com" => 4.121000000000003,
"__SUMMARY__" => 0,
}
`);
Expand All @@ -459,25 +463,25 @@ Map {
describe('#findMainDocument', () => {
it('should find the main document', async () => {
const records = await NetworkRecords.request(devtoolsLog, {computedCache: new Map()});
const mainDocument = NetworkAnalyzer.findResourceForUrl(records, 'https://pwa.rocks/');
assert.equal(mainDocument.url, 'https://pwa.rocks/');
const mainDocument = NetworkAnalyzer.findResourceForUrl(records, 'https://www.paulirish.com/');
assert.equal(mainDocument.url, 'https://www.paulirish.com/');
});

it('should find the main document if the URL includes a fragment', async () => {
const records = await NetworkRecords.request(devtoolsLog, {computedCache: new Map()});
const mainDocument = NetworkAnalyzer.findResourceForUrl(records, 'https://pwa.rocks/#info');
assert.equal(mainDocument.url, 'https://pwa.rocks/');
const mainDocument = NetworkAnalyzer.findResourceForUrl(records, 'https://www.paulirish.com/#info');
assert.equal(mainDocument.url, 'https://www.paulirish.com/');
});
});

describe('#resolveRedirects', () => {
it('should resolve to the same document when no redirect', async () => {
const records = await NetworkRecords.request(devtoolsLog, {computedCache: new Map()});

const mainDocument = NetworkAnalyzer.findResourceForUrl(records, 'https://pwa.rocks/');
const mainDocument = NetworkAnalyzer.findResourceForUrl(records, 'https://www.paulirish.com/');
const finalDocument = NetworkAnalyzer.resolveRedirects(mainDocument);
assert.equal(mainDocument.url, finalDocument.url);
assert.equal(finalDocument.url, 'https://pwa.rocks/');
assert.equal(finalDocument.url, 'https://www.paulirish.com/');
});

it('should resolve to the final document with redirects', async () => {
Expand Down
Loading