Unverified Commit 428d7d7f authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

dispose devices on cleanupAtFinish() for run_cold.dart (#42668)

parent daa7143c
...@@ -168,6 +168,10 @@ class ColdRunner extends ResidentRunner { ...@@ -168,6 +168,10 @@ class ColdRunner extends ResidentRunner {
@override @override
Future<void> cleanupAtFinish() async { Future<void> cleanupAtFinish() async {
for (FlutterDevice flutterDevice in flutterDevices) {
flutterDevice.device.dispose();
}
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
} }
......
...@@ -43,7 +43,6 @@ void main() { ...@@ -43,7 +43,6 @@ void main() {
} }
}); });
group('dart-flags option', () { group('dart-flags option', () {
setUpAll(() { setUpAll(() {
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) { when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
...@@ -84,8 +85,82 @@ void main() { ...@@ -84,8 +85,82 @@ void main() {
Logger: () => mockLogger, Logger: () => mockLogger,
}); });
}); });
group('cleanupAtFinish()', () {
MockFlutterDevice mockFlutterDeviceFactory(Device device) {
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) => Future<void>.value(null));
when(mockFlutterDevice.device).thenReturn(device);
return mockFlutterDevice;
}
testUsingContext('disposes each device', () async {
final MockDevice mockDevice1 = MockDevice();
final MockDevice mockDevice2 = MockDevice();
final MockFlutterDevice mockFlutterDevice1 = mockFlutterDeviceFactory(mockDevice1);
final MockFlutterDevice mockFlutterDevice2 = mockFlutterDeviceFactory(mockDevice2);
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice1, mockFlutterDevice2];
await ColdRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
).cleanupAtFinish();
verify(mockDevice1.dispose());
verify(mockFlutterDevice1.stopEchoingDeviceLog());
verify(mockDevice2.dispose());
verify(mockFlutterDevice2.stopEchoingDeviceLog());
});
});
group('cold run', () {
BufferLogger mockLogger;
setUp(() {
mockLogger = BufferLogger();
});
testUsingContext('returns 1 if not prebuilt mode & mainPath does not exist', () async {
final MockDevice mockDevice = MockDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.device).thenReturn(mockDevice);
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final int result = await ColdRunner(devices).run();
expect(result, 1);
expect(mockLogger.errorText, matches(r'Tried to run .*, but that file does not exist\.'));
expect(mockLogger.errorText, matches(r'Consider using the -t option to specify the Dart file to start\.'));
}, overrides: <Type, Generator>{
Logger: () => mockLogger,
});
testUsingContext('calls runCold on attached device', () async {
final MockDevice mockDevice = MockDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.device).thenReturn(mockDevice);
when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route')
)).thenAnswer((Invocation invocation) => Future<int>.value(1));
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final MockFile applicationBinary = MockFile();
final int result = await ColdRunner(
devices,
applicationBinary: applicationBinary,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
).run();
expect(result, 1);
verify(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route'),
));
}, overrides: <Type, Generator>{
Logger: () => mockLogger,
});
});
} }
class MockFile extends Mock implements File {}
class MockFlutterDevice extends Mock implements FlutterDevice {}
class MockDevice extends Mock implements Device { class MockDevice extends Mock implements Device {
MockDevice() { MockDevice() {
when(isSupported()).thenReturn(true); when(isSupported()).thenReturn(true);
......
...@@ -337,6 +337,36 @@ void main() { ...@@ -337,6 +337,36 @@ void main() {
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true), HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
}); });
}); });
group('hot cleanupAtFinish()', () {
MockFlutterDevice mockFlutterDeviceFactory(Device device) {
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) => Future<void>.value(null));
when(mockFlutterDevice.device).thenReturn(device);
return mockFlutterDevice;
}
testUsingContext('disposes each device', () async {
final MockDevice mockDevice1 = MockDevice();
final MockDevice mockDevice2 = MockDevice();
final MockFlutterDevice mockFlutterDevice1 = mockFlutterDeviceFactory(mockDevice1);
final MockFlutterDevice mockFlutterDevice2 = mockFlutterDeviceFactory(mockDevice2);
final List<FlutterDevice> devices = <FlutterDevice>[
mockFlutterDevice1,
mockFlutterDevice2,
];
await HotRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
).cleanupAtFinish();
verify(mockDevice1.dispose());
verify(mockFlutterDevice1.stopEchoingDeviceLog());
verify(mockDevice2.dispose());
verify(mockFlutterDevice2.stopEchoingDeviceLog());
});
});
} }
class MockDevFs extends Mock implements DevFS {} class MockDevFs extends Mock implements DevFS {}
...@@ -349,6 +379,8 @@ class MockDevice extends Mock implements Device { ...@@ -349,6 +379,8 @@ class MockDevice extends Mock implements Device {
} }
} }
class MockFlutterDevice extends Mock implements FlutterDevice {}
class TestFlutterDevice extends FlutterDevice { class TestFlutterDevice extends FlutterDevice {
TestFlutterDevice({ TestFlutterDevice({
@required Device device, @required Device device,
......
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