Some fixes for the microbenchmarks (#7781)
* Return null from VM.mainView if no view exists
* Retry in connectToServiceProtocol if a view is not yet available
* Do not explicitly call exit from the benchmarks - it will not cleanly shut down the engine
diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart
index 2c14b44..9d940ea 100644
--- a/packages/flutter_tools/lib/src/resident_runner.dart
+++ b/packages/flutter_tools/lib/src/resident_runner.dart
@@ -15,6 +15,7 @@
import 'asset.dart';
+import 'base/common.dart';
import 'base/logger.dart';
import 'build_info.dart';
import 'dart/dependencies.dart';
@@ -172,8 +173,15 @@
// Refresh the view list.
await vmService.vm.refreshViews();
+ for (int i = 0; vmService.vm.mainView == null && i < 5; i++) {
+ // If the VM doesn't yet have a view, wait for one to show up.
+ printTrace('Waiting for Flutter view');
+ await new Future<Null>.delayed(new Duration(seconds: 1));
+ await vmService.vm.refreshViews();
+ }
currentView = vmService.vm.mainView;
- assert(currentView != null);
+ if (currentView == null)
+ throwToolExit('No Flutter view is available');
// Listen for service protocol connection to close.
vmService.done.whenComplete(() {
diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart
index a8034af..7830000 100644
--- a/packages/flutter_tools/lib/src/vmservice.dart
+++ b/packages/flutter_tools/lib/src/vmservice.dart
@@ -686,7 +686,7 @@
}
FlutterView get mainView {
- return _viewCache.values.first;
+ return _viewCache.values.isEmpty ? null : _viewCache.values.first;
}
}