Skip to content

Commit

Permalink
core(network): fix time units in network quiet calc
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed May 21, 2024
1 parent f30413b commit d2fbd59
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/computed/metrics/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ export {InteractiveComputed as Interactive};

/**
* @typedef TimePeriod
* @property {number} start
* @property {number} end
* @property {number} start In ms.
* @property {number} end In ms.
*/
6 changes: 3 additions & 3 deletions core/gather/driver/network-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
/**
* Finds all time periods where the number of inflight requests is less than or equal to the
* number of allowed concurrent requests.
* The time periods returned are in ms.
* @param {Array<LH.Artifacts.NetworkRequest>} requests
* @param {number} allowedConcurrentRequests
* @param {number=} endTime
Expand All @@ -215,10 +216,9 @@ class NetworkMonitor extends NetworkMonitorEventEmitter {
if (UrlUtils.isNonNetworkProtocol(request.protocol)) return;
if (request.protocol === 'ws' || request.protocol === 'wss') return;

// convert the network timestamp to ms
timeBoundaries.push({time: request.networkRequestTime * 1000, isStart: true});
timeBoundaries.push({time: request.networkRequestTime, isStart: true});
if (request.finished) {
timeBoundaries.push({time: request.networkEndTime * 1000, isStart: false});
timeBoundaries.push({time: request.networkEndTime, isStart: false});
}
});

Expand Down
4 changes: 2 additions & 2 deletions core/test/computed/metrics/interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function generateNetworkRecords(partialRecords, timeOrigin) {
statusCode: item.statusCode || 200,
requestMethod: item.requestMethod || 'GET',
finished: typeof item.finished === 'undefined' ? true : item.finished,
networkRequestTime: (item.start + timeOriginInMs) / 1000,
networkEndTime: item.end === -1 ? -1 : (item.end + timeOriginInMs) / 1000,
networkRequestTime: item.start + timeOriginInMs,
networkEndTime: item.end === -1 ? -1 : item.end + timeOriginInMs,
};
return /** @type {LH.Artifacts.NetworkRequest} */ (record);
});
Expand Down
16 changes: 8 additions & 8 deletions core/test/gather/driver/network-monitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ describe('NetworkMonitor', () => {

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 0);
expect(periods).toEqual([
{start: 1000, end: 2000},
{start: 3000, end: 4000},
{start: 5000, end: Infinity},
{start: 1, end: 2},
{start: 3, end: 4},
{start: 5, end: Infinity},
]);
});

Expand All @@ -404,7 +404,7 @@ describe('NetworkMonitor', () => {
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 2);
expect(periods).toEqual([{start: 1500, end: Infinity}]);
expect(periods).toEqual([{start: 1.5, end: Infinity}]);
});

it('should handle unfinished requests', () => {
Expand All @@ -421,9 +421,9 @@ describe('NetworkMonitor', () => {

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 2);
expect(periods).toEqual([
{start: 1500, end: 2000},
{start: 3000, end: 4000},
{start: 5000, end: 5500},
{start: 1.5, end: 2},
{start: 3, end: 4},
{start: 5, end: 5.5},
]);
});

Expand All @@ -435,7 +435,7 @@ describe('NetworkMonitor', () => {
];

const periods = NetworkMonitor.findNetworkQuietPeriods(records, 0);
expect(periods).toEqual([{start: 1000, end: Infinity}]);
expect(periods).toEqual([{start: 1, end: Infinity}]);
});

it('should handle iframe requests', () => {
Expand Down

0 comments on commit d2fbd59

Please sign in to comment.