Fix race condition in flutter test when passing --serve-observatory (#123556)
`flutter test` wasn't awaiting the `_serveObservatory` request which was causing a race condition in the `flutter test should respect --serve-observatory` test in `test/integration.general/test_test.dart`. Related to https://github.com/flutter/flutter/issues/123516
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
// 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' as io; // flutter_ignore: dart_io_import;
|
||||
|
||||
@@ -180,21 +178,19 @@ class FlutterTesterTestDevice extends TestDevice {
|
||||
}
|
||||
|
||||
logger.printTrace('Connecting to service protocol: $forwardingUri');
|
||||
final Future<FlutterVmService> localVmService = connectToVmService(
|
||||
final FlutterVmService vmService = await connectToVmServiceImpl(
|
||||
forwardingUri!,
|
||||
compileExpression: compileExpression,
|
||||
logger: logger,
|
||||
);
|
||||
unawaited(localVmService.then((FlutterVmService vmservice) async {
|
||||
logger.printTrace('test $id: Successfully connected to service protocol: $forwardingUri');
|
||||
if (debuggingOptions.serveObservatory) {
|
||||
try {
|
||||
await vmservice.callMethodWrapper('_serveObservatory');
|
||||
} on vm_service.RPCError {
|
||||
logger.printWarning('Unable to enable Observatory');
|
||||
}
|
||||
logger.printTrace('test $id: Successfully connected to service protocol: $forwardingUri');
|
||||
if (debuggingOptions.serveObservatory) {
|
||||
try {
|
||||
await vmService.callMethodWrapper('_serveObservatory');
|
||||
} on vm_service.RPCError {
|
||||
logger.printWarning('Unable to enable Observatory');
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
if (debuggingOptions.startPaused && !machine!) {
|
||||
logger.printStatus('The Dart VM service is listening on $forwardingUri');
|
||||
@@ -268,6 +264,20 @@ class FlutterTesterTestDevice extends TestDevice {
|
||||
);
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
@protected
|
||||
Future<FlutterVmService> connectToVmServiceImpl(
|
||||
Uri httpUri, {
|
||||
CompileExpression? compileExpression,
|
||||
required Logger logger,
|
||||
}) {
|
||||
return connectToVmService(
|
||||
httpUri,
|
||||
compileExpression: compileExpression,
|
||||
logger: logger,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _startDevTools(Uri forwardingUri, DartDevelopmentService? dds) async {
|
||||
_devToolsLauncher = DevtoolsLauncher.instance;
|
||||
logger.printTrace('test $id: Serving DevTools...');
|
||||
|
||||
@@ -14,12 +14,13 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/test/flutter_tester_device.dart';
|
||||
import 'package:flutter_tools/src/test/font_config_manager.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:stream_channel/stream_channel.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/fake_process_manager.dart';
|
||||
import '../src/fake_vm_services.dart';
|
||||
|
||||
void main() {
|
||||
late FakePlatform platform;
|
||||
@@ -251,6 +252,17 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice {
|
||||
return dds;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FlutterVmService> connectToVmServiceImpl(
|
||||
Uri httpUri, {
|
||||
CompileExpression? compileExpression,
|
||||
required Logger logger,
|
||||
}) async {
|
||||
return FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(method: '_serveObservatory'),
|
||||
]).vmService;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<HttpServer> bind(InternetAddress? host, int port) async => FakeHttpServer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user