Unverified Commit fa491fc9 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Close platform when tests are complete (dispose compiler and delete font files) (#34685)

parent b9932d55
...@@ -68,12 +68,14 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType, ...@@ -68,12 +68,14 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType,
InternetAddressType.IPv6: InternetAddress.loopbackIPv6, InternetAddressType.IPv6: InternetAddress.loopbackIPv6,
}; };
typedef PlatformPluginRegistration = void Function(FlutterPlatform platform);
/// Configure the `test` package to work with Flutter. /// Configure the `test` package to work with Flutter.
/// ///
/// On systems where each [FlutterPlatform] is only used to run one test suite /// On systems where each [FlutterPlatform] is only used to run one test suite
/// (that is, one Dart file with a `*_test.dart` file name and a single `void /// (that is, one Dart file with a `*_test.dart` file name and a single `void
/// main()`), you can set an observatory port explicitly. /// main()`), you can set an observatory port explicitly.
void installHook({ FlutterPlatform installHook({
@required String shellPath, @required String shellPath,
TestWatcher watcher, TestWatcher watcher,
bool enableObservatory = false, bool enableObservatory = false,
...@@ -91,12 +93,20 @@ void installHook({ ...@@ -91,12 +93,20 @@ void installHook({
Uri projectRootDirectory, Uri projectRootDirectory,
FlutterProject flutterProject, FlutterProject flutterProject,
String icudtlPath, String icudtlPath,
PlatformPluginRegistration platformPluginRegistration
}) { }) {
assert(enableObservatory || (!startPaused && observatoryPort == null)); assert(enableObservatory || (!startPaused && observatoryPort == null));
// registerPlatformPlugin can be injected for testing since it's not very mock-friendly.
platformPluginRegistration ??= (FlutterPlatform platform) {
hack.registerPlatformPlugin( hack.registerPlatformPlugin(
<Runtime>[Runtime.vm], <Runtime>[Runtime.vm],
() { () {
return FlutterPlatform( return platform;
}
);
};
final FlutterPlatform platform = FlutterPlatform(
shellPath: shellPath, shellPath: shellPath,
watcher: watcher, watcher: watcher,
machine: machine, machine: machine,
...@@ -115,8 +125,8 @@ void installHook({ ...@@ -115,8 +125,8 @@ void installHook({
flutterProject: flutterProject, flutterProject: flutterProject,
icudtlPath: icudtlPath, icudtlPath: icudtlPath,
); );
} platformPluginRegistration(platform);
); return platform;
} }
/// Generates the bootstrap entry point script that will be used to launch an /// Generates the bootstrap entry point script that will be used to launch an
......
...@@ -105,7 +105,7 @@ Future<int> runTests( ...@@ -105,7 +105,7 @@ Future<int> runTests(
final InternetAddressType serverType = final InternetAddressType serverType =
ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4; ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4;
loader.installHook( final loader.FlutterPlatform platform = loader.installHook(
shellPath: shellPath, shellPath: shellPath,
watcher: watcher, watcher: watcher,
enableObservatory: enableObservatory, enableObservatory: enableObservatory,
...@@ -145,5 +145,6 @@ Future<int> runTests( ...@@ -145,5 +145,6 @@ Future<int> runTests(
return exitCode; return exitCode;
} finally { } finally {
fs.currentDirectory = saved; fs.currentDirectory = saved;
await platform.close();
} }
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/test/flutter_platform.dart'; import 'package:flutter_tools/src/test/flutter_platform.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
...@@ -24,6 +25,58 @@ void main() { ...@@ -24,6 +25,58 @@ void main() {
flutterPlatfrom.loadChannel('test1.dart', MockPlatform()); flutterPlatfrom.loadChannel('test1.dart', MockPlatform());
expect(() => flutterPlatfrom.loadChannel('test2.dart', MockPlatform()), throwsA(isA<ToolExit>())); expect(() => flutterPlatfrom.loadChannel('test2.dart', MockPlatform()), throwsA(isA<ToolExit>()));
}); });
testUsingContext('installHook creates a FlutterPlatform', () {
expect(() => installHook(
shellPath: 'abc',
enableObservatory: false,
startPaused: true
), throwsA(isA<AssertionError>()));
expect(() => installHook(
shellPath: 'abc',
enableObservatory: false,
startPaused: false,
observatoryPort: 123
), throwsA(isA<AssertionError>()));
FlutterPlatform capturedPlatform;
final Map<String, String> expectedPrecompiledDillFiles = <String, String>{'Key': 'Value'};
final FlutterPlatform flutterPlatform = installHook(
shellPath: 'abc',
enableObservatory: true,
machine: true,
startPaused: true,
disableServiceAuthCodes: true,
port: 100,
precompiledDillPath: 'def',
precompiledDillFiles: expectedPrecompiledDillFiles,
trackWidgetCreation: true,
updateGoldens: true,
buildTestAssets: true,
observatoryPort: 200,
serverType: InternetAddressType.IPv6,
icudtlPath: 'ghi',
platformPluginRegistration: (FlutterPlatform platform) {
capturedPlatform = platform;
});
expect(identical(capturedPlatform, flutterPlatform), equals(true));
expect(flutterPlatform.shellPath, equals('abc'));
expect(flutterPlatform.enableObservatory, equals(true));
expect(flutterPlatform.machine, equals(true));
expect(flutterPlatform.startPaused, equals(true));
expect(flutterPlatform.disableServiceAuthCodes, equals(true));
expect(flutterPlatform.port, equals(100));
expect(flutterPlatform.host, InternetAddress.loopbackIPv6);
expect(flutterPlatform.explicitObservatoryPort, equals(200));
expect(flutterPlatform.precompiledDillPath, equals('def'));
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
expect(flutterPlatform.trackWidgetCreation, equals(true));
expect(flutterPlatform.updateGoldens, equals(true));
expect(flutterPlatform.buildTestAssets, equals(true));
expect(flutterPlatform.icudtlPath, equals('ghi'));
});
}); });
} }
......
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