[infra] Handle shutdown failures in webdriver browser controllers

Change-Id: I4c3b457e9167e08afef2e3f4aff92d2b3011a02f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260541
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: William Hesse <whesse@google.com>
This commit is contained in:
William Hesse 2022-09-22 15:23:37 +00:00 committed by Commit Bot
parent 043f18f843
commit 51b6dba707

View file

@ -251,13 +251,6 @@ abstract class Browser {
/// Starts the browser loading the given url
Future<bool> start(String url);
/// Called when the driver page is requested, that is, when the browser first
/// contacts the test server. At this time, it's safe to assume that the
/// browser process has started and opened its first window.
///
/// This is used by [Safari] to ensure the browser window has focus.
Future<Null> onDriverPageRequested() => Future.value();
@override
String toString() => '$runtimeType';
}
@ -266,6 +259,7 @@ abstract class WebDriverBrowser extends Browser {
WebDriver? _driver;
final int _port;
final Map<String, dynamic> _desiredCapabilities;
bool _terminated = false;
WebDriverBrowser(this._port, this._desiredCapabilities);
@ -273,6 +267,7 @@ abstract class WebDriverBrowser extends Browser {
Future<bool> start(String url) async {
_logEvent('Starting $this browser on: $url');
await _createDriver();
if (_terminated) return false;
await _driver!.get(url);
try {
_logEvent('Got version: ${await version}');
@ -287,11 +282,13 @@ abstract class WebDriverBrowser extends Browser {
for (var i = 5; i >= 0; i--) {
// Give the driver process some time to be ready to accept connections.
await Future.delayed(const Duration(seconds: 1));
if (_terminated) return;
try {
_driver = await createDriver(
uri: Uri.parse('http://localhost:$_port/'),
desired: _desiredCapabilities);
} catch (error) {
if (_terminated) return;
if (i > 0) {
_logEvent(
'Failed to create driver ($i retries left).\nError: $error');
@ -307,6 +304,7 @@ abstract class WebDriverBrowser extends Browser {
@override
Future<bool> close() async {
_terminated = true;
await _driver?.quit();
// Give the driver process some time to be quit the browser.
return true;
@ -1255,7 +1253,6 @@ class BrowserTestingServer {
}
Future<String> getDriverPage(String browserId) async {
await testRunner.browserStatus[browserId]?.browser.onDriverPageRequested();
var errorReportingUrl =
"http://$localIp:${errorReportingServer.port}/$browserId";
var driverContent = """