[flutter_tools] use temp dir for tester dill, use desktop log reader (#75922)
On windows, its not possible to run 2 integration tests using flutter-tester simultaneously. This is due to the flutter tester using a fixed location for its dill output. Use a temp dir instead. Also replace the custom log reader in flutter-tester with the desktop log reader, and ensure stopApp waits for the process exit code. Fixes #75534
This commit is contained in:
@@ -18,7 +18,7 @@ import '../base/logger.dart';
|
||||
import '../base/os.dart';
|
||||
import '../build_info.dart';
|
||||
import '../bundle.dart';
|
||||
import '../convert.dart';
|
||||
import '../desktop_device.dart';
|
||||
import '../devfs.dart';
|
||||
import '../device.dart';
|
||||
import '../project.dart';
|
||||
@@ -53,14 +53,15 @@ class FlutterTesterDevice extends Device {
|
||||
@required ProcessManager processManager,
|
||||
@required FlutterVersion flutterVersion,
|
||||
@required Logger logger,
|
||||
@required String buildDirectory,
|
||||
// TODO(jonahwilliams): remove once g3 rolls.
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
String buildDirectory,
|
||||
@required FileSystem fileSystem,
|
||||
@required Artifacts artifacts,
|
||||
@required OperatingSystemUtils operatingSystemUtils,
|
||||
}) : _processManager = processManager,
|
||||
_flutterVersion = flutterVersion,
|
||||
_logger = logger,
|
||||
_buildDirectory = buildDirectory,
|
||||
_fileSystem = fileSystem,
|
||||
_artifacts = artifacts,
|
||||
_operatingSystemUtils = operatingSystemUtils,
|
||||
@@ -74,7 +75,6 @@ class FlutterTesterDevice extends Device {
|
||||
final ProcessManager _processManager;
|
||||
final FlutterVersion _flutterVersion;
|
||||
final Logger _logger;
|
||||
final String _buildDirectory;
|
||||
final FileSystem _fileSystem;
|
||||
final Artifacts _artifacts;
|
||||
final OperatingSystemUtils _operatingSystemUtils;
|
||||
@@ -109,8 +109,7 @@ class FlutterTesterDevice extends Device {
|
||||
@override
|
||||
void clearLogs() { }
|
||||
|
||||
final _FlutterTesterDeviceLogReader _logReader =
|
||||
_FlutterTesterDeviceLogReader();
|
||||
final DesktopLogReader _logReader = DesktopLogReader();
|
||||
|
||||
@override
|
||||
DeviceLogReader getLogReader({
|
||||
@@ -155,11 +154,13 @@ class FlutterTesterDevice extends Device {
|
||||
return LaunchResult.failed();
|
||||
}
|
||||
|
||||
final String assetDirPath = _fileSystem.path.join(_buildDirectory, 'flutter_assets');
|
||||
final Directory assetDirectory = _fileSystem.systemTempDirectory
|
||||
.createTempSync('flutter-tester');
|
||||
final String applicationKernelFilePath = getKernelPathForTransformerOptions(
|
||||
_fileSystem.path.join(_buildDirectory, 'flutter-tester-app.dill'),
|
||||
_fileSystem.path.join(assetDirectory.path, 'flutter-tester-app.dill'),
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
);
|
||||
|
||||
// Build assets and perform initial compilation.
|
||||
await BundleBuilder().build(
|
||||
buildInfo: buildInfo,
|
||||
@@ -168,6 +169,7 @@ class FlutterTesterDevice extends Device {
|
||||
trackWidgetCreation: buildInfo.trackWidgetCreation,
|
||||
platform: getTargetPlatformForName(getNameForHostPlatform(_operatingSystemUtils.hostPlatform)),
|
||||
treeShakeIcons: buildInfo.treeShakeIcons,
|
||||
assetDirPath: assetDirectory.path,
|
||||
);
|
||||
|
||||
final List<String> command = <String>[
|
||||
@@ -176,7 +178,7 @@ class FlutterTesterDevice extends Device {
|
||||
'--non-interactive',
|
||||
'--enable-dart-profiling',
|
||||
'--packages=${debuggingOptions.buildInfo.packagesPath}',
|
||||
'--flutter-assets-dir=$assetDirPath',
|
||||
'--flutter-assets-dir=${assetDirectory.path}',
|
||||
if (debuggingOptions.startPaused)
|
||||
'--start-paused',
|
||||
if (debuggingOptions.disableServiceAuthCodes)
|
||||
@@ -194,15 +196,6 @@ class FlutterTesterDevice extends Device {
|
||||
'FLUTTER_TEST': 'true',
|
||||
},
|
||||
);
|
||||
_process.stdout
|
||||
.transform<String>(utf8.decoder)
|
||||
.transform<String>(const LineSplitter())
|
||||
.listen(_logReader.addLine);
|
||||
_process.stderr
|
||||
.transform<String>(utf8.decoder)
|
||||
.transform<String>(const LineSplitter())
|
||||
.listen(_logReader.addLine);
|
||||
|
||||
if (!debuggingOptions.debuggingEnabled) {
|
||||
return LaunchResult.succeeded();
|
||||
}
|
||||
@@ -213,6 +206,7 @@ class FlutterTesterDevice extends Device {
|
||||
devicePort: debuggingOptions.deviceVmServicePort,
|
||||
ipv6: ipv6,
|
||||
);
|
||||
_logReader.initializeProcess(_process);
|
||||
|
||||
final Uri observatoryUri = await observatoryDiscovery.uri;
|
||||
if (observatoryUri != null) {
|
||||
@@ -273,14 +267,15 @@ class FlutterTesterDevices extends PollingDeviceDiscovery {
|
||||
@required ProcessManager processManager,
|
||||
@required Logger logger,
|
||||
@required FlutterVersion flutterVersion,
|
||||
@required Config config,
|
||||
// TODO(jonahwilliams): remove after flutter rolls
|
||||
// ignore: avoid_unused_constructor_parameters
|
||||
Config config,
|
||||
@required OperatingSystemUtils operatingSystemUtils,
|
||||
}) : _testerDevice = FlutterTesterDevice(
|
||||
kTesterDeviceId,
|
||||
fileSystem: fileSystem,
|
||||
artifacts: artifacts,
|
||||
processManager: processManager,
|
||||
buildDirectory: getBuildDirectory(config, fileSystem),
|
||||
logger: logger,
|
||||
flutterVersion: flutterVersion,
|
||||
operatingSystemUtils: operatingSystemUtils,
|
||||
@@ -304,22 +299,3 @@ class FlutterTesterDevices extends PollingDeviceDiscovery {
|
||||
return showFlutterTesterDevice ? <Device>[_testerDevice] : <Device>[];
|
||||
}
|
||||
}
|
||||
|
||||
class _FlutterTesterDeviceLogReader extends DeviceLogReader {
|
||||
final StreamController<String> _logLinesController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
@override
|
||||
int get appPid => 0;
|
||||
|
||||
@override
|
||||
Stream<String> get logLines => _logLinesController.stream;
|
||||
|
||||
@override
|
||||
String get name => 'flutter tester log reader';
|
||||
|
||||
void addLine(String line) => _logLinesController.add(line);
|
||||
|
||||
@override
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
@@ -149,18 +151,18 @@ void main() {
|
||||
testUsingContext('performs a build and starts in debug mode', () async {
|
||||
final FlutterTesterApp app = FlutterTesterApp.fromCurrentDirectory(fileSystem);
|
||||
final Uri observatoryUri = Uri.parse('http://127.0.0.1:6666/');
|
||||
final String assetsPath = fileSystem.path.join('build', 'flutter_assets');
|
||||
final String dillPath = fileSystem.path.join('build', 'flutter-tester-app.dill');
|
||||
final Completer<void> completer = Completer<void>();
|
||||
fakeProcessManager.addCommand(FakeCommand(
|
||||
command: <String>[
|
||||
command: const <String>[
|
||||
'Artifact.flutterTester',
|
||||
'--run-forever',
|
||||
'--non-interactive',
|
||||
'--enable-dart-profiling',
|
||||
'--packages=.packages',
|
||||
'--flutter-assets-dir=$assetsPath',
|
||||
dillPath,
|
||||
'--flutter-assets-dir=/.tmp_rand0/flutter-testerrand0',
|
||||
'/.tmp_rand0/flutter-testerrand0/flutter-tester-app.dill',
|
||||
],
|
||||
completer: completer,
|
||||
stdout:
|
||||
'''
|
||||
Observatory listening on $observatoryUri
|
||||
|
||||
Reference in New Issue
Block a user