Skip to content

Commit

Permalink
core(driver): warn about remaining inflight requests urls (#14963)
Browse files Browse the repository at this point in the history
Thanks @doteric! Nice test :)
  • Loading branch information
doteric committed May 4, 2023
1 parent 6403654 commit 60117f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
12 changes: 12 additions & 0 deletions core/gather/driver/wait-for-condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ async function waitForFullyLoaded(session, networkMonitor, options) {
throw new LighthouseError(LighthouseError.errors.PAGE_HUNG);
}

// Log remaining inflight requests if any.
const inflightRequestUrls = networkMonitor
.getInflightRequests()
.map((request) => request.url);
if (inflightRequestUrls.length > 0) {
log.warn(
'waitFor',
'Remaining inflight requests URLs',
inflightRequestUrls
);
}

return {timedOut: true};
};
});
Expand Down
29 changes: 27 additions & 2 deletions core/test/gather/driver/wait-for-condition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

import log from 'lighthouse-logger';

import * as wait from '../../../gather/driver/wait-for-condition.js';
import {
mockCommands,
Expand Down Expand Up @@ -63,7 +65,7 @@ describe('waitForFullyLoaded()', () => {

beforeEach(() => {
session = {sendCommand: fnAny().mockResolvedValue(), setNextProtocolTimeout: fnAny()};
networkMonitor = {};
networkMonitor = {getInflightRequests: fnAny().mockReturnValue([])};

const overrides = {
waitForFcp: createMockWaitForFn(),
Expand Down Expand Up @@ -179,10 +181,17 @@ describe('waitForFullyLoaded()', () => {
expect(await loadPromise).toMatchObject({timedOut: false});
});

it('should timeout when not resolved fast enough', async () => {
it('should timeout and warn when not resolved fast enough', async () => {
options._waitForTestOverrides.waitForLoadEvent = createMockWaitForFn();
options._waitForTestOverrides.waitForNetworkIdle = createMockWaitForFn();
options._waitForTestOverrides.waitForCPUIdle = createMockWaitForFn();
networkMonitor.getInflightRequests.mockReturnValue([{url: 'https://example.com'}]);

/** @type {Array<unknown>} */
const warnings = [];
/** @param {unknown} evt */
const saveWarning = evt => warnings.push(evt);
log.events.on('warning', saveWarning);

const loadPromise = makePromiseInspectable(wait.waitForFullyLoaded(
session,
Expand All @@ -203,6 +212,22 @@ describe('waitForFullyLoaded()', () => {
expect(options._waitForTestOverrides.waitForLoadEvent.getMockCancelFn()).toHaveBeenCalled();
expect(options._waitForTestOverrides.waitForNetworkIdle.getMockCancelFn()).toHaveBeenCalled();
expect(options._waitForTestOverrides.waitForCPUIdle.getMockCancelFn()).toHaveBeenCalled();
// Check for warn logs
log.events.off('warning', saveWarning);
expect(warnings).toEqual([
[
'waitFor',
'Timed out waiting for page load. Checking if page is hung...',
],
[
'waitFor',
'Remaining inflight requests URLs',
[
'https://example.com',
],
],
]);

expect(await loadPromise).toMatchObject({timedOut: true});
});

Expand Down

0 comments on commit 60117f8

Please sign in to comment.