Unverified Commit 46b8ea8f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[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
parent 13d051f2
...@@ -18,7 +18,7 @@ import '../base/logger.dart'; ...@@ -18,7 +18,7 @@ import '../base/logger.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../bundle.dart'; import '../bundle.dart';
import '../convert.dart'; import '../desktop_device.dart';
import '../devfs.dart'; import '../devfs.dart';
import '../device.dart'; import '../device.dart';
import '../project.dart'; import '../project.dart';
...@@ -53,14 +53,15 @@ class FlutterTesterDevice extends Device { ...@@ -53,14 +53,15 @@ class FlutterTesterDevice extends Device {
@required ProcessManager processManager, @required ProcessManager processManager,
@required FlutterVersion flutterVersion, @required FlutterVersion flutterVersion,
@required Logger logger, @required Logger logger,
@required String buildDirectory, // TODO(jonahwilliams): remove once g3 rolls.
// ignore: avoid_unused_constructor_parameters
String buildDirectory,
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required Artifacts artifacts, @required Artifacts artifacts,
@required OperatingSystemUtils operatingSystemUtils, @required OperatingSystemUtils operatingSystemUtils,
}) : _processManager = processManager, }) : _processManager = processManager,
_flutterVersion = flutterVersion, _flutterVersion = flutterVersion,
_logger = logger, _logger = logger,
_buildDirectory = buildDirectory,
_fileSystem = fileSystem, _fileSystem = fileSystem,
_artifacts = artifacts, _artifacts = artifacts,
_operatingSystemUtils = operatingSystemUtils, _operatingSystemUtils = operatingSystemUtils,
...@@ -74,7 +75,6 @@ class FlutterTesterDevice extends Device { ...@@ -74,7 +75,6 @@ class FlutterTesterDevice extends Device {
final ProcessManager _processManager; final ProcessManager _processManager;
final FlutterVersion _flutterVersion; final FlutterVersion _flutterVersion;
final Logger _logger; final Logger _logger;
final String _buildDirectory;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Artifacts _artifacts; final Artifacts _artifacts;
final OperatingSystemUtils _operatingSystemUtils; final OperatingSystemUtils _operatingSystemUtils;
...@@ -109,8 +109,7 @@ class FlutterTesterDevice extends Device { ...@@ -109,8 +109,7 @@ class FlutterTesterDevice extends Device {
@override @override
void clearLogs() { } void clearLogs() { }
final _FlutterTesterDeviceLogReader _logReader = final DesktopLogReader _logReader = DesktopLogReader();
_FlutterTesterDeviceLogReader();
@override @override
DeviceLogReader getLogReader({ DeviceLogReader getLogReader({
...@@ -155,11 +154,13 @@ class FlutterTesterDevice extends Device { ...@@ -155,11 +154,13 @@ class FlutterTesterDevice extends Device {
return LaunchResult.failed(); return LaunchResult.failed();
} }
final String assetDirPath = _fileSystem.path.join(_buildDirectory, 'flutter_assets'); final Directory assetDirectory = _fileSystem.systemTempDirectory
.createTempSync('flutter-tester');
final String applicationKernelFilePath = getKernelPathForTransformerOptions( final String applicationKernelFilePath = getKernelPathForTransformerOptions(
_fileSystem.path.join(_buildDirectory, 'flutter-tester-app.dill'), _fileSystem.path.join(assetDirectory.path, 'flutter-tester-app.dill'),
trackWidgetCreation: buildInfo.trackWidgetCreation, trackWidgetCreation: buildInfo.trackWidgetCreation,
); );
// Build assets and perform initial compilation. // Build assets and perform initial compilation.
await BundleBuilder().build( await BundleBuilder().build(
buildInfo: buildInfo, buildInfo: buildInfo,
...@@ -168,6 +169,7 @@ class FlutterTesterDevice extends Device { ...@@ -168,6 +169,7 @@ class FlutterTesterDevice extends Device {
trackWidgetCreation: buildInfo.trackWidgetCreation, trackWidgetCreation: buildInfo.trackWidgetCreation,
platform: getTargetPlatformForName(getNameForHostPlatform(_operatingSystemUtils.hostPlatform)), platform: getTargetPlatformForName(getNameForHostPlatform(_operatingSystemUtils.hostPlatform)),
treeShakeIcons: buildInfo.treeShakeIcons, treeShakeIcons: buildInfo.treeShakeIcons,
assetDirPath: assetDirectory.path,
); );
final List<String> command = <String>[ final List<String> command = <String>[
...@@ -176,7 +178,7 @@ class FlutterTesterDevice extends Device { ...@@ -176,7 +178,7 @@ class FlutterTesterDevice extends Device {
'--non-interactive', '--non-interactive',
'--enable-dart-profiling', '--enable-dart-profiling',
'--packages=${debuggingOptions.buildInfo.packagesPath}', '--packages=${debuggingOptions.buildInfo.packagesPath}',
'--flutter-assets-dir=$assetDirPath', '--flutter-assets-dir=${assetDirectory.path}',
if (debuggingOptions.startPaused) if (debuggingOptions.startPaused)
'--start-paused', '--start-paused',
if (debuggingOptions.disableServiceAuthCodes) if (debuggingOptions.disableServiceAuthCodes)
...@@ -194,15 +196,6 @@ class FlutterTesterDevice extends Device { ...@@ -194,15 +196,6 @@ class FlutterTesterDevice extends Device {
'FLUTTER_TEST': 'true', '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) { if (!debuggingOptions.debuggingEnabled) {
return LaunchResult.succeeded(); return LaunchResult.succeeded();
} }
...@@ -213,6 +206,7 @@ class FlutterTesterDevice extends Device { ...@@ -213,6 +206,7 @@ class FlutterTesterDevice extends Device {
devicePort: debuggingOptions.deviceVmServicePort, devicePort: debuggingOptions.deviceVmServicePort,
ipv6: ipv6, ipv6: ipv6,
); );
_logReader.initializeProcess(_process);
final Uri observatoryUri = await observatoryDiscovery.uri; final Uri observatoryUri = await observatoryDiscovery.uri;
if (observatoryUri != null) { if (observatoryUri != null) {
...@@ -273,14 +267,15 @@ class FlutterTesterDevices extends PollingDeviceDiscovery { ...@@ -273,14 +267,15 @@ class FlutterTesterDevices extends PollingDeviceDiscovery {
@required ProcessManager processManager, @required ProcessManager processManager,
@required Logger logger, @required Logger logger,
@required FlutterVersion flutterVersion, @required FlutterVersion flutterVersion,
@required Config config, // TODO(jonahwilliams): remove after flutter rolls
// ignore: avoid_unused_constructor_parameters
Config config,
@required OperatingSystemUtils operatingSystemUtils, @required OperatingSystemUtils operatingSystemUtils,
}) : _testerDevice = FlutterTesterDevice( }) : _testerDevice = FlutterTesterDevice(
kTesterDeviceId, kTesterDeviceId,
fileSystem: fileSystem, fileSystem: fileSystem,
artifacts: artifacts, artifacts: artifacts,
processManager: processManager, processManager: processManager,
buildDirectory: getBuildDirectory(config, fileSystem),
logger: logger, logger: logger,
flutterVersion: flutterVersion, flutterVersion: flutterVersion,
operatingSystemUtils: operatingSystemUtils, operatingSystemUtils: operatingSystemUtils,
...@@ -304,22 +299,3 @@ class FlutterTesterDevices extends PollingDeviceDiscovery { ...@@ -304,22 +299,3 @@ class FlutterTesterDevices extends PollingDeviceDiscovery {
return showFlutterTesterDevice ? <Device>[_testerDevice] : <Device>[]; 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 @@ ...@@ -4,6 +4,8 @@
// @dart = 2.8 // @dart = 2.8
import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
...@@ -149,18 +151,18 @@ void main() { ...@@ -149,18 +151,18 @@ void main() {
testUsingContext('performs a build and starts in debug mode', () async { testUsingContext('performs a build and starts in debug mode', () async {
final FlutterTesterApp app = FlutterTesterApp.fromCurrentDirectory(fileSystem); final FlutterTesterApp app = FlutterTesterApp.fromCurrentDirectory(fileSystem);
final Uri observatoryUri = Uri.parse('http://127.0.0.1:6666/'); final Uri observatoryUri = Uri.parse('http://127.0.0.1:6666/');
final String assetsPath = fileSystem.path.join('build', 'flutter_assets'); final Completer<void> completer = Completer<void>();
final String dillPath = fileSystem.path.join('build', 'flutter-tester-app.dill');
fakeProcessManager.addCommand(FakeCommand( fakeProcessManager.addCommand(FakeCommand(
command: <String>[ command: const <String>[
'Artifact.flutterTester', 'Artifact.flutterTester',
'--run-forever', '--run-forever',
'--non-interactive', '--non-interactive',
'--enable-dart-profiling', '--enable-dart-profiling',
'--packages=.packages', '--packages=.packages',
'--flutter-assets-dir=$assetsPath', '--flutter-assets-dir=/.tmp_rand0/flutter-testerrand0',
dillPath, '/.tmp_rand0/flutter-testerrand0/flutter-tester-app.dill',
], ],
completer: completer,
stdout: stdout:
''' '''
Observatory listening on $observatoryUri Observatory listening on $observatoryUri
......
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