Unverified Commit d6d2e89f authored by Yegor's avatar Yegor Committed by GitHub

finer grained logging of Chromium launch sequence (#135078)

Log the details of how Chromium is about to be launched prior to running
the Chromium command, as well as the path to the Chromium executable.

This should improve our understanding of what's happening here:
https://github.com/flutter/flutter/issues/132654#issuecomment-1726630123
parent b433b175
...@@ -171,14 +171,23 @@ class ChromiumLauncher { ...@@ -171,14 +171,23 @@ class ChromiumLauncher {
throwToolExit('Only one instance of chrome can be started.'); throwToolExit('Only one instance of chrome can be started.');
} }
if (_logger.isVerbose) {
_logger.printTrace('Launching Chromium (url = $url, headless = $headless, skipCheck = $skipCheck, debugPort = $debugPort)');
}
final String chromeExecutable = _browserFinder(_platform, _fileSystem); final String chromeExecutable = _browserFinder(_platform, _fileSystem);
if (_logger.isVerbose && !_platform.isWindows) { if (_logger.isVerbose) {
// The "--version" argument is not supported on Windows. _logger.printTrace('Will use Chromium executable at $chromeExecutable');
final ProcessResult versionResult = await _processManager.run(<String>[chromeExecutable, '--version']);
_logger.printTrace('Using ${versionResult.stdout}'); if (!_platform.isWindows) {
// The "--version" argument is not supported on Windows.
final ProcessResult versionResult = await _processManager.run(<String>[chromeExecutable, '--version']);
_logger.printTrace('Using ${versionResult.stdout}');
}
} }
final Directory userDataDir = _fileSystem.systemTempDirectory final Directory userDataDir = _fileSystem.systemTempDirectory
.createTempSync('flutter_tools_chrome_device.'); .createTempSync('flutter_tools_chrome_device.');
......
...@@ -44,6 +44,7 @@ void main() { ...@@ -44,6 +44,7 @@ void main() {
late Platform platform; late Platform platform;
late FakeProcessManager processManager; late FakeProcessManager processManager;
late OperatingSystemUtils operatingSystemUtils; late OperatingSystemUtils operatingSystemUtils;
late BufferLogger testLogger;
setUp(() { setUp(() {
exceptionHandler = FileExceptionHandler(); exceptionHandler = FileExceptionHandler();
...@@ -59,13 +60,41 @@ void main() { ...@@ -59,13 +60,41 @@ void main() {
processManager: processManager, processManager: processManager,
operatingSystemUtils: operatingSystemUtils, operatingSystemUtils: operatingSystemUtils,
browserFinder: findChromeExecutable, browserFinder: findChromeExecutable,
logger: BufferLogger.test(), logger: testLogger = BufferLogger.test(),
); );
}); });
Future<Chromium> testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
if (testLogger.isVerbose) {
processManager.addCommand(const FakeCommand(
command: <String>[
'example_chrome',
'--version',
],
stdout: 'Chromium 115',
));
}
processManager.addCommand(FakeCommand(
command: <String>[
'example_chrome',
'--user-data-dir=$userDataDir',
'--remote-debugging-port=12345',
...kChromeArgs,
'example_url',
],
stderr: kDevtoolsStderr,
));
return chromeLauncher.launch(
'example_url',
skipCheck: true,
);
}
testWithoutContext('can launch chrome and connect to the devtools', () async { testWithoutContext('can launch chrome and connect to the devtools', () async {
await expectReturnsNormallyLater( await expectReturnsNormallyLater(
_testLaunchChrome( testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0', '/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager, processManager,
chromeLauncher, chromeLauncher,
...@@ -73,15 +102,44 @@ void main() { ...@@ -73,15 +102,44 @@ void main() {
); );
}); });
testWithoutContext('can launch chrome in verbose mode', () async {
chromeLauncher = ChromiumLauncher(
fileSystem: fileSystem,
platform: platform,
processManager: processManager,
operatingSystemUtils: operatingSystemUtils,
browserFinder: findChromeExecutable,
logger: testLogger = BufferLogger.test(verbose: true),
);
await expectReturnsNormallyLater(
testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager,
chromeLauncher,
)
);
expect(
testLogger.traceText.trim(),
'Launching Chromium (url = example_url, headless = false, skipCheck = true, debugPort = null)\n'
'Will use Chromium executable at example_chrome\n'
'Using Chromium 115\n'
'[CHROME]: \n'
'[CHROME]: \n'
'[CHROME]: DevTools listening',
);
});
testWithoutContext('cannot have two concurrent instances of chrome', () async { testWithoutContext('cannot have two concurrent instances of chrome', () async {
await _testLaunchChrome( await testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0', '/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager, processManager,
chromeLauncher, chromeLauncher,
); );
await expectToolExitLater( await expectToolExitLater(
_testLaunchChrome( testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand1', '/.tmp_rand0/flutter_tools_chrome_device.rand1',
processManager, processManager,
chromeLauncher, chromeLauncher,
...@@ -91,7 +149,7 @@ void main() { ...@@ -91,7 +149,7 @@ void main() {
}); });
testWithoutContext('can launch new chrome after stopping a previous chrome', () async { testWithoutContext('can launch new chrome after stopping a previous chrome', () async {
final Chromium chrome = await _testLaunchChrome( final Chromium chrome = await testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0', '/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager, processManager,
chromeLauncher, chromeLauncher,
...@@ -99,7 +157,7 @@ void main() { ...@@ -99,7 +157,7 @@ void main() {
await chrome.close(); await chrome.close();
await expectReturnsNormallyLater( await expectReturnsNormallyLater(
_testLaunchChrome( testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand1', '/.tmp_rand0/flutter_tools_chrome_device.rand1',
processManager, processManager,
chromeLauncher, chromeLauncher,
...@@ -630,24 +688,6 @@ void main() { ...@@ -630,24 +688,6 @@ void main() {
}); });
} }
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
processManager.addCommand(FakeCommand(
command: <String>[
'example_chrome',
'--user-data-dir=$userDataDir',
'--remote-debugging-port=12345',
...kChromeArgs,
'example_url',
],
stderr: kDevtoolsStderr,
));
return chromeLauncher.launch(
'example_url',
skipCheck: true,
);
}
/// Fake chrome connection that fails to get tabs a few times. /// Fake chrome connection that fails to get tabs a few times.
class FakeChromeConnection extends Fake implements ChromeConnection { class FakeChromeConnection extends Fake implements ChromeConnection {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment