Unverified Commit 75a44a29 authored by Ben Konyi's avatar Ben Konyi Committed by GitHub

[ Web ] Register service extensions with DDS, not DWDS (#79479)

parent 437e32b9
......@@ -17,6 +17,7 @@ import 'package:mime/mime.dart' as mime;
import 'package:package_config/package_config.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as shelf;
import 'package:vm_service/vm_service.dart' as vm_service;
import '../artifacts.dart';
import '../asset.dart';
......@@ -35,6 +36,7 @@ import '../dart/package_map.dart';
import '../devfs.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../vmservice.dart';
import '../web/bootstrap.dart';
import '../web/chrome.dart';
import '../web/compile.dart';
......@@ -592,10 +594,11 @@ class WebAssetServer implements AssetReader {
}
class ConnectionResult {
ConnectionResult(this.appConnection, this.debugConnection);
ConnectionResult(this.appConnection, this.debugConnection, this.vmService);
final AppConnection appConnection;
final DebugConnection debugConnection;
final vm_service.VmService vmService;
}
/// The web specific DevFS implementation.
......@@ -665,8 +668,12 @@ class WebDevFS implements DevFS {
if (firstConnection.isCompleted) {
appConnection.runMain();
} else {
final vm_service.VmService vmService = await createVmServiceDelegate(
Uri.parse(debugConnection.uri),
logger: globals.logger,
);
firstConnection
.complete(ConnectionResult(appConnection, debugConnection));
.complete(ConnectionResult(appConnection, debugConnection, vmService));
}
} on Exception catch (error, stackTrace) {
if (!firstConnection.isCompleted) {
......
......@@ -155,7 +155,7 @@ class ResidentWebRunner extends ResidentRunner {
if (_instance != null) {
return _instance;
}
final vmservice.VmService service =_connectionResult?.debugConnection?.vmService;
final vmservice.VmService service =_connectionResult?.vmService;
final Uri websocketUri = Uri.parse(_connectionResult.debugConnection.uri);
final Uri httpUri = _httpUriFromWebsocketUri(websocketUri);
return _instance ??= FlutterVmService(service, wsAddress: websocketUri, httpAddress: httpUri);
......@@ -835,7 +835,7 @@ class ResidentWebRunner extends ResidentRunner {
_connectionResult.appConnection.runMain();
} else {
StreamSubscription<void> resumeSub;
resumeSub = _connectionResult.debugConnection.vmService.onDebugEvent
resumeSub = _vmService.service.onDebugEvent
.listen((vmservice.Event event) {
if (event.type == vmservice.EventKind.kResume) {
_connectionResult.appConnection.runMain();
......
......@@ -326,6 +326,22 @@ Future<FlutterVmService> connectToVmService(
);
}
Future<vm_service.VmService> createVmServiceDelegate(
Uri wsUri, {
io.CompressionOptions compression = io.CompressionOptions.compressionDefault,
@required Logger logger,
}) async {
final io.WebSocket channel = await _openChannel(wsUri.toString(), compression: compression, logger: logger);
return vm_service.VmService(
channel,
channel.add,
log: null,
disposeHandler: () async {
await channel.close();
},
);
}
Future<FlutterVmService> _connect(
Uri httpUri, {
ReloadSources reloadSources,
......@@ -338,14 +354,8 @@ Future<FlutterVmService> _connect(
@required Logger logger,
}) async {
final Uri wsUri = httpUri.replace(scheme: 'ws', path: urlContext.join(httpUri.path, 'ws'));
final io.WebSocket channel = await _openChannel(wsUri.toString(), compression: compression, logger: logger);
final vm_service.VmService delegateService = vm_service.VmService(
channel,
channel.add,
log: null,
disposeHandler: () async {
await channel.close();
},
final vm_service.VmService delegateService = await createVmServiceDelegate(
wsUri, compression: compression, logger: logger,
);
final vm_service.VmService service = await setUpVmService(
......
......@@ -130,7 +130,11 @@ void main() {
when(mockFlutterDevice.devFS).thenReturn(mockWebDevFS);
when(mockFlutterDevice.device).thenReturn(mockDevice);
when(mockWebDevFS.connect(any)).thenAnswer((Invocation invocation) async {
return ConnectionResult(mockAppConnection, mockDebugConnection);
return ConnectionResult(
mockAppConnection,
mockDebugConnection,
mockDebugConnection.vmService,
);
});
fileSystem.file('.packages').writeAsStringSync('\n');
});
......
......@@ -63,6 +63,7 @@ abstract class FlutterTestDriver {
Stream<String> get stdout => _stdout.stream;
int get vmServicePort => _vmServiceWsUri.port;
bool get hasExited => _hasExited;
Uri get vmServiceWsUri => _vmServiceWsUri;
String lastTime = '';
void _debugPrint(String message, { String topic = '' }) {
......@@ -219,7 +220,7 @@ abstract class FlutterTestDriver {
return _flutterIsolateId;
}
Future<Isolate> _getFlutterIsolate() async {
Future<Isolate> getFlutterIsolate() async {
final Isolate isolate = await _vmService.getIsolate(await _getFlutterIsolateId());
return isolate;
}
......@@ -281,7 +282,7 @@ abstract class FlutterTestDriver {
// Cancel the subscription on either of the above.
await pauseSubscription.cancel();
return _getFlutterIsolate();
return getFlutterIsolate();
},
task: 'Waiting for isolate to pause',
);
......@@ -294,7 +295,7 @@ abstract class FlutterTestDriver {
Future<Isolate> stepOut({ bool waitForNextPause = true }) => _resume(StepOption.kOut, waitForNextPause);
Future<bool> isAtAsyncSuspension() async {
final Isolate isolate = await _getFlutterIsolate();
final Isolate isolate = await getFlutterIsolate();
return isolate.pauseEvent.atAsyncSuspension == true;
}
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import '../integration.shard/test_data/basic_project.dart';
import '../integration.shard/test_driver.dart';
import '../integration.shard/test_utils.dart';
import '../src/common.dart';
void main() {
Directory tempDir;
final BasicProjectWithUnaryMain project = BasicProjectWithUnaryMain();
FlutterRunTestDriver flutter;
group('Clients of flutter run on web with DDS enabled', () {
setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
await project.setUpIn(tempDir);
flutter = FlutterRunTestDriver(tempDir, spawnDdsInstance: true);
});
tearDown(() async {
await flutter.stop();
tryToDelete(tempDir);
});
testWithoutContext('can validate flutter version', () async {
await flutter.run(
withDebugger: true, chrome: true,
additionalCommandArgs: <String>['--verbose']);
expect(flutter.vmServiceWsUri, isNotNull);
final VmService client =
await vmServiceConnectUri('${flutter.vmServiceWsUri}');
await validateFlutterVersion(client);
});
testWithoutContext('can validate flutter version in parallel', () async {
await flutter.run(
withDebugger: true, chrome: true,
additionalCommandArgs: <String>['--verbose']);
expect(flutter.vmServiceWsUri, isNotNull);
final VmService client1 =
await vmServiceConnectUri('${flutter.vmServiceWsUri}');
final VmService client2 =
await vmServiceConnectUri('${flutter.vmServiceWsUri}');
await Future.wait(<Future<void>>[
validateFlutterVersion(client1),
validateFlutterVersion(client2)]
);
}, skip: 'DDS failure: https://github.com/dart-lang/sdk/issues/45569');
});
group('Clients of flutter run on web with DDS disabled', () {
setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
await project.setUpIn(tempDir);
flutter = FlutterRunTestDriver(tempDir, spawnDdsInstance: false);
});
tearDown(() async {
await flutter.stop();
tryToDelete(tempDir);
});
testWithoutContext('can validate flutter version', () async {
await flutter.run(
withDebugger: true, chrome: true,
additionalCommandArgs: <String>['--verbose']);
expect(flutter.vmServiceWsUri, isNotNull);
final VmService client =
await vmServiceConnectUri('${flutter.vmServiceWsUri}');
await validateFlutterVersion(client);
});
testWithoutContext('can validate flutter version in parallel', () async {
await flutter.run(
withDebugger: true, chrome: true,
additionalCommandArgs: <String>['--verbose']);
expect(flutter.vmServiceWsUri, isNotNull);
final VmService client1 =
await vmServiceConnectUri('${flutter.vmServiceWsUri}');
final VmService client2 =
await vmServiceConnectUri('${flutter.vmServiceWsUri}');
await Future.wait(<Future<void>>[
validateFlutterVersion(client1),
validateFlutterVersion(client2)]
);
});
});
}
Future<void> validateFlutterVersion(VmService client) async {
String method;
final Future<dynamic> registration = expectLater(
client.onEvent('Service'),
emitsThrough(predicate((Event e) {
if (e.kind == EventKind.kServiceRegistered &&
e.service == 'flutterVersion') {
method = e.method;
return true;
}
return false;
}))
);
await client.streamListen('Service');
await registration;
await client.streamCancel('Service');
final dynamic version1 = await client.callServiceExtension(method);
expect(version1, const TypeMatcher<Success>()
.having((Success r) => r.type, 'type', 'Success')
.having((Success r) => r.json['frameworkVersion'], 'frameworkVersion', isNotNull));
await client.dispose();
}
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