Skip to content

Commit

Permalink
core(lantern): remove last usages of Lighthouse NetworkRequest (#16067)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Jun 12, 2024
1 parent 2244edc commit 8c5f8a2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions core/lib/lantern/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import * as Lantern from './types/lantern.js';
import {BaseNode} from '../../lib/lantern/base-node.js';
import {RESOURCE_TYPES} from '../../lib/network-request.js';
import {BaseNode} from './base-node.js';
import {RESOURCE_TYPES} from '../network-request.js';

/** @typedef {import('./base-node.js').Node} Node */
/** @typedef {import('./network-node.js').NetworkNode} NetworkNode */
Expand Down
28 changes: 1 addition & 27 deletions core/test/lib/lantern/simulator/network-analyzer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as Lantern from '../../../../lib/lantern/types/lantern.js';
import {NetworkAnalyzer} from '../../../../lib/lantern/simulator/network-analyzer.js';
import * as TraceEngineComputationData from '../../../../lib/lantern/trace-engine-computation-data.js';
import {readJson} from '../../../test-utils.js';
import {NetworkRequest} from '../../../../lib/network-request.js';
import {runTraceEngine} from '../metrics/metric-test-utils.js';

const trace = readJson('../../../fixtures/artifacts/paul/trace.json', import.meta);
Expand All @@ -37,7 +36,7 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
const url = opts.url || 'https://example.com';
if (opts.networkRequestTime) opts.networkRequestTime *= 1000;
if (opts.networkEndTime) opts.networkEndTime *= 1000;
const request = Object.assign(
return Object.assign(
{
url,
requestId: recordId++,
Expand All @@ -52,7 +51,6 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
},
opts
);
return NetworkRequest.asLanternNetworkRequest(request);
}

beforeEach(() => {
Expand Down Expand Up @@ -273,22 +271,6 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
assertCloseEnough(result.avg, resultApprox.avg, 30);
assertCloseEnough(result.median, resultApprox.median, 30);
});

it('should use lrStatistics when needed', () => {
global.isLightrider = true;
const request = createRecord({timing: {}, lrStatistics: {TCPMs: 100}});
const result = NetworkAnalyzer.estimateRTTByOrigin([request]);
const expected = {min: 50, max: 50, avg: 50, median: 50};
assert.deepStrictEqual(result.get('https://example.com'), expected);
});

it('should use lrStatistics when needed (h3)', () => {
global.isLightrider = true;
const request = createRecord({protocol: 'h3', timing: {}, lrStatistics: {TCPMs: 100}});
const result = NetworkAnalyzer.estimateRTTByOrigin([request]);
const expected = {min: 100, max: 100, avg: 100, median: 100};
assert.deepStrictEqual(result.get('https://example.com'), expected);
});
});

describe('#estimateServerResponseTimeByOrigin', () => {
Expand Down Expand Up @@ -338,14 +320,6 @@ describe('DependencyGraph/Simulator/NetworkAnalyzer', () => {
assertCloseEnough(result.avg, resultApprox.avg, 30);
assertCloseEnough(result.median, resultApprox.median, 30);
});

it('should use lrStatistics when needed', () => {
global.isLightrider = true;
const request = createRecord({timing: {}, lrStatistics: {TCPMs: 1, requestMs: 100}});
const result = NetworkAnalyzer.estimateServerResponseTimeByOrigin([request]);
const expected = {min: 100, max: 100, avg: 100, median: 100};
assert.deepStrictEqual(result.get('https://example.com'), expected);
});
});

describe('#estimateThroughput', () => {
Expand Down
4 changes: 1 addition & 3 deletions core/test/lib/lantern/simulator/simulator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {CPUNode} from '../../../../lib/lantern/cpu-node.js';
import {Simulator} from '../../../../lib/lantern/simulator/simulator.js';
import {DNSCache} from '../../../../lib/lantern/simulator/dns-cache.js';
import {readJson} from '../../../test-utils.js';
import {NetworkRequest} from '../../../../lib/network-request.js';
import * as TraceEngineComputationData from '../../../../lib/lantern/trace-engine-computation-data.js';
import {runTraceEngine} from '../metrics/metric-test-utils.js';

Expand All @@ -39,7 +38,7 @@ function request(opts) {
delete opts.startTime;
delete opts.endTime;

const request = Object.assign({
return Object.assign({
requestId: opts.requestId || nextRequestId++,
url,
transferSize: opts.transferSize || 1000,
Expand All @@ -49,7 +48,6 @@ function request(opts) {
rendererStartTime,
networkEndTime,
}, opts);
return NetworkRequest.asLanternNetworkRequest(request);
}

function cpuTask({tid, ts, duration}) {
Expand Down
31 changes: 31 additions & 0 deletions core/test/lib/network-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ describe('NetworkRequest', () => {
});
});

describe('#asLanternNetworkRequest', () => {
it('uses lrStatistics to make timings', () => {
global.isLightrider = true;
const request = NetworkRequest.asLanternNetworkRequest({
protocol: 'h2',
timing: {},
lrStatistics: {TCPMs: 100, requestMs: 1000},
});
expect(request.timing).toStrictEqual({
connectStart: 0,
connectEnd: 100,
sslStart: 50,
sslEnd: 100,
});
expect(request.serverResponseTime).toStrictEqual(1000);
});

it('uses lrStatistics to make timings (h3)', () => {
global.isLightrider = true;
const request = NetworkRequest.asLanternNetworkRequest({
protocol: 'h3',
timing: {},
lrStatistics: {TCPMs: 100},
});
expect(request.timing).toStrictEqual({
connectStart: 0,
connectEnd: 100,
});
});
});

describe('#isSecureRequest', () => {
const isSecureRequest = NetworkRequest.isSecureRequest;

Expand Down

0 comments on commit 8c5f8a2

Please sign in to comment.