Unverified Commit 6b17840c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Don't try to flutterExit if isolate is still paused (#36199)

parent 1387e7fe
...@@ -175,8 +175,20 @@ class FlutterDevice { ...@@ -175,8 +175,20 @@ class FlutterDevice {
if (flutterViews == null || flutterViews.isEmpty) if (flutterViews == null || flutterViews.isEmpty)
return; return;
final List<Future<void>> futures = <Future<void>>[]; final List<Future<void>> futures = <Future<void>>[];
// If any of the flutter views are paused, we might not be able to
// cleanly exit since the service extension may not have been registered.
if (flutterViews.any((FlutterView view) {
return view != null &&
view.uiIsolate != null &&
view.uiIsolate.pauseEvent.isPauseEvent;
}
)) {
await device.stopApp(package);
return;
}
for (FlutterView view in flutterViews) { for (FlutterView view in flutterViews) {
if (view != null && view.uiIsolate != null) { if (view != null && view.uiIsolate != null) {
assert(!view.uiIsolate.pauseEvent.isPauseEvent);
futures.add(view.uiIsolate.flutterExit()); futures.add(view.uiIsolate.flutterExit());
} }
} }
......
...@@ -28,6 +28,7 @@ void main() { ...@@ -28,6 +28,7 @@ void main() {
MockFlutterView mockFlutterView; MockFlutterView mockFlutterView;
ResidentRunner residentRunner; ResidentRunner residentRunner;
MockDevice mockDevice; MockDevice mockDevice;
MockIsolate mockIsolate;
setUp(() { setUp(() {
testbed = Testbed(setup: () { testbed = Testbed(setup: () {
...@@ -44,6 +45,7 @@ void main() { ...@@ -44,6 +45,7 @@ void main() {
mockVMService = MockVMService(); mockVMService = MockVMService();
mockDevFS = MockDevFS(); mockDevFS = MockDevFS();
mockFlutterView = MockFlutterView(); mockFlutterView = MockFlutterView();
mockIsolate = MockIsolate();
// DevFS Mocks // DevFS Mocks
when(mockDevFS.lastCompiled).thenReturn(DateTime(2000)); when(mockDevFS.lastCompiled).thenReturn(DateTime(2000));
when(mockDevFS.sources).thenReturn(<Uri>[]); when(mockDevFS.sources).thenReturn(<Uri>[]);
...@@ -73,7 +75,7 @@ void main() { ...@@ -73,7 +75,7 @@ void main() {
mockFlutterView mockFlutterView
]); ]);
when(mockFlutterDevice.device).thenReturn(mockDevice); when(mockFlutterDevice.device).thenReturn(mockDevice);
when(mockFlutterView.uiIsolate).thenReturn(MockIsolate()); when(mockFlutterView.uiIsolate).thenReturn(mockIsolate);
when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) async { }); when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) async { });
when(mockFlutterDevice.observatoryUris).thenReturn(<Uri>[ when(mockFlutterDevice.observatoryUris).thenReturn(<Uri>[
testUri, testUri,
...@@ -97,6 +99,12 @@ void main() { ...@@ -97,6 +99,12 @@ void main() {
final Completer<void> result = Completer<void>.sync(); final Completer<void> result = Completer<void>.sync();
return result.future; return result.future;
}); });
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
return Future<Map<String, Object>>.value(null);
});
when(mockIsolate.flutterExit()).thenAnswer((Invocation invocation) {
return Future<Map<String, Object>>.value(null);
});
}); });
test('Can attach to device successfully', () => testbed.run(() async { test('Can attach to device successfully', () => testbed.run(() async {
...@@ -203,6 +211,40 @@ void main() { ...@@ -203,6 +211,40 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Usage: () => MockUsage(), Usage: () => MockUsage(),
})); }));
group('FlutterDevice' , () {
test('Will not exit a paused isolate', () => testbed.run(() async {
final TestFlutterDevice flutterDevice = TestFlutterDevice(
mockDevice,
<FlutterView>[ mockFlutterView ],
);
final MockServiceEvent mockServiceEvent = MockServiceEvent();
when(mockServiceEvent.isPauseEvent).thenReturn(true);
when(mockIsolate.pauseEvent).thenReturn(mockServiceEvent);
when(mockDevice.supportsFlutterExit).thenReturn(true);
await flutterDevice.exitApps();
verifyNever(mockIsolate.flutterExit());
verify(mockDevice.stopApp(any)).called(1);
}));
test('Will exit an un-paused isolate', () => testbed.run(() async {
final TestFlutterDevice flutterDevice = TestFlutterDevice(
mockDevice,
<FlutterView> [mockFlutterView ],
);
final MockServiceEvent mockServiceEvent = MockServiceEvent();
when(mockServiceEvent.isPauseEvent).thenReturn(false);
when(mockIsolate.pauseEvent).thenReturn(mockServiceEvent);
when(mockDevice.supportsFlutterExit).thenReturn(true);
await flutterDevice.exitApps();
verify(mockIsolate.flutterExit()).called(1);
}));
});
}); });
} }
...@@ -213,3 +255,12 @@ class MockDevFS extends Mock implements DevFS {} ...@@ -213,3 +255,12 @@ class MockDevFS extends Mock implements DevFS {}
class MockIsolate extends Mock implements Isolate {} class MockIsolate extends Mock implements Isolate {}
class MockDevice extends Mock implements Device {} class MockDevice extends Mock implements Device {}
class MockUsage extends Mock implements Usage {} class MockUsage extends Mock implements Usage {}
class MockServiceEvent extends Mock implements ServiceEvent {}
class TestFlutterDevice extends FlutterDevice {
TestFlutterDevice(Device device, this.views)
: super(device, buildMode: BuildMode.debug, trackWidgetCreation: false);
@override
final List<FlutterView> views;
}
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