From f8c9e1bb6769d2f2f7430825910701dcf715ecaf Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 24 Jun 2020 12:14:58 -0700 Subject: [PATCH] [flutter_tools] de-flake integration tests (#60221) The vm_service_integration test flake is caused by trying to call the method before the framework is initialized (and the extension added). The run errors failure is caused by the error taking some time to propagate to the harness --- .../flutter_run_with_error_test.dart | 19 +++++++++++++++++- .../vmservice_integration_test.dart | 20 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart b/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart index 3cf44ba88b..5ffc17c0a4 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_run_with_error_test.dart @@ -31,10 +31,27 @@ void main() { test('flutter run reports an early error in an application', () async { final StringBuffer stdout = StringBuffer(); - _flutter.stdout.listen(stdout.writeln); await _flutter.run(startPaused: true, withDebugger: true, structuredErrors: true); await _flutter.resume(); + + final Completer completer = Completer(); + bool lineFound = false; + + await Future(() async { + _flutter.stdout.listen((String line) { + stdout.writeln(line); + if (line.startsWith('Another exception was thrown') && !lineFound) { + lineFound = true; + completer.complete(); + } + }); + await completer.future; + }).timeout(const Duration(seconds: 15), onTimeout: () { + // Complete anyway in case we don't see the 'Another exception' line. + completer.complete(); + }); + await _flutter.stop(); expect(stdout.toString(), contains(_exceptionStart)); diff --git a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart index 5bacd4fbca..ae2c6f395b 100644 --- a/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart +++ b/packages/flutter_tools/test/integration.shard/vmservice_integration_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; import 'dart:io'; // ignore: dart_io_import import 'package:file/file.dart'; @@ -89,7 +90,7 @@ void main() { }); test('ext.flutter.brightnessOverride can toggle window brightness', () async { - final IsolateRef isolate = (await vmService.getVM()).isolates.first; + final Isolate isolate = await waitForExtension(vmService); final Response response = await vmService.callServiceExtension( 'ext.flutter.brightnessOverride', isolateId: isolate.id, @@ -129,3 +130,20 @@ void main() { // TODO(devoncarew): These tests fail on cirrus-ci windows. }, skip: Platform.isWindows); } + +Future waitForExtension(VmService vmService) async { + final Completer completer = Completer(); + await vmService.streamListen(EventStreams.kExtension); + vmService.onExtensionEvent.listen((Event event) { + if (event.json['extensionKind'] == 'Flutter.FrameworkInitialization') { + completer.complete(); + } + }); + final IsolateRef isolateRef = (await vmService.getVM()).isolates.first; + final Isolate isolate = await vmService.getIsolate(isolateRef.id); + if (isolate.extensionRPCs.contains('ext.flutter.brightnessOverride')) { + return isolate; + } + await completer.future; + return isolate; +}