Terminate simulator app on "q" (#113581)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_devicelab/framework/devices.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/framework/ios.dart';
|
||||
import 'package:flutter_devicelab/framework/task_result.dart';
|
||||
import 'package:flutter_devicelab/tasks/hot_mode_tests.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
await task(() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.ios;
|
||||
String? simulatorDeviceId;
|
||||
try {
|
||||
await testWithNewIOSSimulator('TestHotReloadSim', (String deviceId) async {
|
||||
simulatorDeviceId = deviceId;
|
||||
// This isn't actually a benchmark test, so do not use the returned `benchmarkScoreKeys` result.
|
||||
await createHotModeTest(deviceIdOverride: deviceId, checkAppRunningOnLocalDevice: true)();
|
||||
});
|
||||
} finally {
|
||||
await removeIOSimulator(simulatorDeviceId);
|
||||
}
|
||||
|
||||
return TaskResult.success(null);
|
||||
});
|
||||
}
|
||||
@@ -6,5 +6,5 @@ import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/tasks/hot_mode_tests.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
await task(createHotModeTest(deviceIdOverride: 'linux'));
|
||||
await task(createHotModeTest(deviceIdOverride: 'linux', checkAppRunningOnLocalDevice: true));
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../framework/devices.dart';
|
||||
import '../framework/framework.dart';
|
||||
import '../framework/running_processes.dart';
|
||||
import '../framework/task_result.dart';
|
||||
import '../framework/utils.dart';
|
||||
|
||||
@@ -18,7 +20,11 @@ final Directory flutterGalleryDir = dir(path.join(flutterDirectory.path, 'dev/in
|
||||
const String kSourceLine = 'fontSize: (orientation == Orientation.portrait) ? 32.0 : 24.0';
|
||||
const String kReplacementLine = 'fontSize: (orientation == Orientation.portrait) ? 34.0 : 24.0';
|
||||
|
||||
TaskFunction createHotModeTest({String? deviceIdOverride, Map<String, String>? environment}) {
|
||||
TaskFunction createHotModeTest({
|
||||
String? deviceIdOverride,
|
||||
Map<String, String>? environment,
|
||||
bool checkAppRunningOnLocalDevice = false,
|
||||
}) {
|
||||
// This file is modified during the test and needs to be restored at the end.
|
||||
final File flutterFrameworkSource = file(path.join(
|
||||
flutterDirectory.path, 'packages/flutter/lib/src/widgets/framework.dart',
|
||||
@@ -96,7 +102,7 @@ TaskFunction createHotModeTest({String? deviceIdOverride, Map<String, String>? e
|
||||
}
|
||||
});
|
||||
|
||||
largeReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) {
|
||||
largeReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) async {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
@@ -108,6 +114,9 @@ TaskFunction createHotModeTest({String? deviceIdOverride, Map<String, String>? e
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
if (checkAppRunningOnLocalDevice) {
|
||||
await _checkAppRunning(true);
|
||||
}
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
});
|
||||
@@ -150,6 +159,9 @@ TaskFunction createHotModeTest({String? deviceIdOverride, Map<String, String>? e
|
||||
json.decode(benchmarkFile.readAsStringSync()) as Map<String, dynamic>;
|
||||
}
|
||||
});
|
||||
if (checkAppRunningOnLocalDevice) {
|
||||
await _checkAppRunning(false);
|
||||
}
|
||||
} finally {
|
||||
flutterFrameworkSource.writeAsStringSync(oldContents);
|
||||
}
|
||||
@@ -257,3 +269,23 @@ Future<Map<String, dynamic>> captureReloadData(
|
||||
benchmarkFile.deleteSync();
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> _checkAppRunning(bool shouldBeRunning) async {
|
||||
late Set<RunningProcessInfo> galleryProcesses;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final String exe = Platform.isWindows ? '.exe' : '';
|
||||
galleryProcesses = await getRunningProcesses(
|
||||
processName: 'Flutter Gallery$exe',
|
||||
processManager: const LocalProcessManager(),
|
||||
);
|
||||
|
||||
if (galleryProcesses.isNotEmpty == shouldBeRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the app time to shut down.
|
||||
sleep(const Duration(seconds: 1));
|
||||
}
|
||||
print(galleryProcesses.join('\n'));
|
||||
throw TaskResult.failure('Flutter Gallery app is ${shouldBeRunning ? 'not' : 'still'} running');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user