Skip to content

Commit

Permalink
feat(e2e): support setting Chromium protocol timeout in CLI (#107)
Browse files Browse the repository at this point in the history
Summary: Allow tweaking the Chromium protocol timeout for page crashed with error: 'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'.

Differential Revision: D52742549

fbshipit-source-id: 21b5cfb3b4f1d2bd88a478012185f34505b3e453
  • Loading branch information
JacksonGL authored and facebook-github-bot committed Jan 16, 2024
1 parent 6c82dea commit 73c9fa3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/commands/RunMeasureCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import DisableWebSecurityOption from '../options/e2e/DisableWebSecurityOption';
import EnableJSRewriteOption from '../options/e2e/EnableJSRewriteOption';
import EnableJSInterceptOption from '../options/e2e/EnableJSInterceptOption';
import SetChromiumBinaryOption from '../options/e2e/SetChromiumBinaryOption';
import SetChromiumProtocolTimeoutOption from '../options/e2e/SetChromiumProtocolTimeoutOption';

export default class RunMeasureCommand extends BaseCommand {
getCommandName(): string {
Expand Down Expand Up @@ -73,6 +74,7 @@ export default class RunMeasureCommand extends BaseCommand {
new RemoteBrowserDebugOption(),
new ScenarioFileOption(),
new SetChromiumBinaryOption(),
new SetChromiumProtocolTimeoutOption(),
new SetDeviceOption(),
new SetUserAgentOption(),
new DisableXvfbOption(),
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/WarmupAppCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import DisableWebSecurityOption from '../options/e2e/DisableWebSecurityOption';
import EnableJSRewriteOption from '../options/e2e/EnableJSRewriteOption';
import EnableJSInterceptOption from '../options/e2e/EnableJSInterceptOption';
import SetChromiumBinaryOption from '../options/e2e/SetChromiumBinaryOption';
import SetChromiumProtocolTimeoutOption from '../options/e2e/SetChromiumProtocolTimeoutOption';

export default class FBWarmupAppCommand extends BaseCommand {
getCommandName(): string {
Expand Down Expand Up @@ -59,6 +60,7 @@ export default class FBWarmupAppCommand extends BaseCommand {
new RemoteBrowserDebugOption(),
new ScenarioFileOption(),
new SetChromiumBinaryOption(),
new SetChromiumProtocolTimeoutOption(),
new SetDeviceOption(),
new SetUserAgentOption(),
new DisableXvfbOption(),
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/snapshot/TakeSnapshotCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import EnableJSRewriteOption from '../../options/e2e/EnableJSRewriteOption';
import EnableJSInterceptOption from '../../options/e2e/EnableJSInterceptOption';
import TargetWorkerOption from '../../options/e2e/TargetWorkerOption';
import SetChromiumBinaryOption from '../../options/e2e/SetChromiumBinaryOption';
import SetChromiumProtocolTimeoutOption from '../../options/e2e/SetChromiumProtocolTimeoutOption';

export default class TakeSnapshotCommand extends BaseCommand {
getCommandName(): string {
Expand Down Expand Up @@ -77,6 +78,7 @@ export default class TakeSnapshotCommand extends BaseCommand {
new RemoteBrowserDebugOption(),
new ScenarioFileOption(),
new SetChromiumBinaryOption(),
new SetChromiumProtocolTimeoutOption(),
new SetDeviceOption(),
new SetUserAgentOption(),
new DisableXvfbOption(),
Expand Down
48 changes: 48 additions & 0 deletions packages/cli/src/options/e2e/SetChromiumProtocolTimeoutOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall web_perf_infra
*/
import type {ParsedArgs} from 'minimist';
import {MemLabConfig} from '@memlab/core';

import {info, utils, BaseOption} from '@memlab/core';
import optionConstants from '../lib/OptionConstant';

export default class SetChromiumProtocolTimeoutOption extends BaseOption {
getOptionName(): string {
return optionConstants.optionNames.CHROMIUM_PROTOCOL_TIMEOUT;
}

getDescription(): string {
return (
'set the protocol timeout for chromium connection (in ms). \n' +
'The current default value is 180000, you may want to increase the ' +
'timeout via this flag when the heap snapshot is ' +
'too big (e.g., over 1GB) and the Page crashed with error: ' +
"'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'."
);
}

async parse(config: MemLabConfig, args: ParsedArgs): Promise<void> {
const name = this.getOptionName();
const arg = args[name];
if (arg) {
const timeout = parseInt(arg, 10);
if (Number.isNaN(timeout)) {
utils.haltOrThrow(
`Invalid Chromium protocol timeout value: ${arg}. ` +
'It must be a number.',
);
}
if (config.verbose) {
info.lowLevel(`Set Chromium protocol timeout to ${timeout}.`);
}
config.puppeteerConfig.protocolTimeout = timeout;
}
}
}
1 change: 1 addition & 0 deletions packages/cli/src/options/lib/OptionConstant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const optionNames = {
CONTROL_SNAPSHOT: 'control-snapshot',
CONTROL_WORK_DIR: 'control-work-dir',
CHROMIUM_BINARY: 'chromium-binary',
CHROMIUM_PROTOCOL_TIMEOUT: 'protocol-timeout',
DEVICE: 'device',
DISABLE_WEB_SECURITY: 'disable-web-security',
DISABLE_XVFB: 'disable-xvfb',
Expand Down
10 changes: 10 additions & 0 deletions website/docs/cli/CLI-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ memlab run --scenario /tmp/test-scenario.js --work-dir /tmp/test-1/
* **`--local-puppeteer`**: enable remote browser instance debugging via local puppeteer
* **`--scenario`**: set file path loading test scenario
* **`--chromium-binary`**: set the chromium binary for E2E run
* **`--protocol-timeout`**: set the protocol timeout for chromium connection (in ms).
The current default value is 180000, you may want to increase the timeout via this flag when the heap snapshot is too big (e.g., over 1GB) and the Page crashed with error: 'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'.
* **`--device`**: set the device type to emulate
* **`--user-agent`**: set the UserAgent string in browser (for E2E interaction), otherwise it uses the default UserAgent from Chromium
* **`--disable-xvfb`**: disable Xvfb (X virtual framebuffer) for simulating headful browser rendering
Expand Down Expand Up @@ -508,6 +510,8 @@ memlab measure --scenario /tmp/test-scenario.js --work-dir /tmp/test-1/
* **`--local-puppeteer`**: enable remote browser instance debugging via local puppeteer
* **`--scenario`**: set file path loading test scenario
* **`--chromium-binary`**: set the chromium binary for E2E run
* **`--protocol-timeout`**: set the protocol timeout for chromium connection (in ms).
The current default value is 180000, you may want to increase the timeout via this flag when the heap snapshot is too big (e.g., over 1GB) and the Page crashed with error: 'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'.
* **`--device`**: set the device type to emulate
* **`--user-agent`**: set the UserAgent string in browser (for E2E interaction), otherwise it uses the default UserAgent from Chromium
* **`--disable-xvfb`**: disable Xvfb (X virtual framebuffer) for simulating headful browser rendering
Expand Down Expand Up @@ -543,6 +547,8 @@ memlab warmup --scenario /tmp/test-scenario.js
* **`--local-puppeteer`**: enable remote browser instance debugging via local puppeteer
* **`--scenario`**: set file path loading test scenario
* **`--chromium-binary`**: set the chromium binary for E2E run
* **`--protocol-timeout`**: set the protocol timeout for chromium connection (in ms).
The current default value is 180000, you may want to increase the timeout via this flag when the heap snapshot is too big (e.g., over 1GB) and the Page crashed with error: 'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'.
* **`--device`**: set the device type to emulate
* **`--user-agent`**: set the UserAgent string in browser (for E2E interaction), otherwise it uses the default UserAgent from Chromium
* **`--disable-xvfb`**: disable Xvfb (X virtual framebuffer) for simulating headful browser rendering
Expand Down Expand Up @@ -616,6 +622,8 @@ memlab snapshot --scenario /tmp/test-scenario.js --work-dir /tmp/test-1/
* **`--local-puppeteer`**: enable remote browser instance debugging via local puppeteer
* **`--scenario`**: set file path loading test scenario
* **`--chromium-binary`**: set the chromium binary for E2E run
* **`--protocol-timeout`**: set the protocol timeout for chromium connection (in ms).
The current default value is 180000, you may want to increase the timeout via this flag when the heap snapshot is too big (e.g., over 1GB) and the Page crashed with error: 'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'.
* **`--device`**: set the device type to emulate
* **`--user-agent`**: set the UserAgent string in browser (for E2E interaction), otherwise it uses the default UserAgent from Chromium
* **`--disable-xvfb`**: disable Xvfb (X virtual framebuffer) for simulating headful browser rendering
Expand Down Expand Up @@ -658,6 +666,8 @@ memlab warmup-and-snapshot --scenario /tmp/test-scenario.js --work-dir /tmp/test
* **`--local-puppeteer`**: enable remote browser instance debugging via local puppeteer
* **`--scenario`**: set file path loading test scenario
* **`--chromium-binary`**: set the chromium binary for E2E run
* **`--protocol-timeout`**: set the protocol timeout for chromium connection (in ms).
The current default value is 180000, you may want to increase the timeout via this flag when the heap snapshot is too big (e.g., over 1GB) and the Page crashed with error: 'ProtocolError: HeapProfiler.takeHeapSnapshot timed out'.
* **`--device`**: set the device type to emulate
* **`--user-agent`**: set the UserAgent string in browser (for E2E interaction), otherwise it uses the default UserAgent from Chromium
* **`--disable-xvfb`**: disable Xvfb (X virtual framebuffer) for simulating headful browser rendering
Expand Down

0 comments on commit 73c9fa3

Please sign in to comment.