Hack to prevent Safari from being backgrounded during unit tests. (flutter/engine#53402)

Safari actually pauses execution of our unit tests if the window becomes occluded or non-visible. As such, I am inserting this egregious hack which just makes the Safari window frontmost every 2 seconds so that the unit tests don't get stalled out.

This should fix https://github.com/flutter/flutter/issues/150023
This commit is contained in:
Jackson Gardner
2024-06-14 13:18:32 -07:00
committed by GitHub
parent 6d88e21691
commit 5dd33ba48e
3 changed files with 23 additions and 7 deletions

View File

@@ -1131,7 +1131,7 @@
"recipe": "engine_v2/tester_engine",
"drone_dimensions": [
"device_type=none",
"os=Mac-13",
"os=Mac-13|Mac-14",
"cpu=arm64"
],
"gclient_variables": {
@@ -1164,7 +1164,7 @@
"recipe": "engine_v2/tester_engine",
"drone_dimensions": [
"device_type=none",
"os=Mac-13",
"os=Mac-13|Mac-14",
"cpu=arm64"
],
"gclient_variables": {
@@ -1197,7 +1197,7 @@
"recipe": "engine_v2/tester_engine",
"drone_dimensions": [
"device_type=none",
"os=Mac-13",
"os=Mac-13|Mac-14",
"cpu=arm64"
],
"gclient_variables": {
@@ -1230,7 +1230,7 @@
"recipe": "engine_v2/tester_engine",
"drone_dimensions": [
"device_type=none",
"os=Mac-13",
"os=Mac-13|Mac-14",
"cpu=arm64"
],
"gclient_variables": {
@@ -1263,7 +1263,7 @@
"recipe": "engine_v2/tester_engine",
"drone_dimensions": [
"device_type=none",
"os=Mac-13",
"os=Mac-13|Mac-14",
"cpu=arm64"
],
"gclient_variables": {
@@ -1296,7 +1296,7 @@
"recipe": "engine_v2/tester_engine",
"drone_dimensions": [
"device_type=none",
"os=Mac-13",
"os=Mac-13|Mac-14",
"cpu=arm64"
],
"gclient_variables": {

View File

@@ -113,7 +113,7 @@ Iterable<dynamic> _getAllTestSteps(List<TestSuite> suites) {
suite.runConfig.browser == BrowserName.chrome ||
suite.runConfig.browser == BrowserName.firefox
),
..._getTestStepsForPlatform(suites, 'Mac', specificOS: 'Mac-13', cpu: 'arm64', (TestSuite suite) =>
..._getTestStepsForPlatform(suites, 'Mac', specificOS: 'Mac-13|Mac-14', cpu: 'arm64', (TestSuite suite) =>
suite.runConfig.browser == BrowserName.safari
),
..._getTestStepsForPlatform(suites, 'Windows', (TestSuite suite) =>

View File

@@ -81,14 +81,30 @@ abstract class WebDriverBrowserEnvironment extends BrowserEnvironment {
class WebDriverBrowser extends Browser {
WebDriverBrowser(this._driver, this._url) {
_driver.get(_url);
_activateLoopFuture = () async {
// Some browsers (i.e. Safari) stop actually executing our unit tests if
// their window is occluded or non-visible. This hacky solution of
// re-activating the window every two seconds prevents our unit tests from
// stalling out if the window becomes obscured by some other thing that
// may appear on the system.
while (!_shouldStopActivating) {
await (await _driver.window).setAsActive();
await Future<void>.delayed(const Duration(seconds: 2));
}
}();
}
final WebDriver _driver;
final Uri _url;
final Completer<void> _onExitCompleter = Completer<void>();
bool _shouldStopActivating = false;
late final Future<void> _activateLoopFuture;
@override
Future<void> close() async {
_shouldStopActivating = true;
await _activateLoopFuture;
await (await _driver.window).close();
if (!_onExitCompleter.isCompleted) {
_onExitCompleter.complete();