[ dart:developer ] Add serverWebSocketUri to ServiceProtocolInfo

Adds a convenience getter to ServiceProtocolInfo which transforms the VM
Service HTTP URI into a valid web socket URI that can be used to connect
to the VM service.

Fixes https://github.com/dart-lang/sdk/issues/42968.

TEST=runtime/observatory/tests/service/developer_server_control_test.dart

Change-Id: Ib15de1f1a9b26ac5cf45f55a53014761a6fa7900
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194209
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
This commit is contained in:
Ben Konyi 2021-04-07 20:02:17 +00:00 committed by commit-bot@chromium.org
parent 8f832e2c6b
commit d18d3d837f
4 changed files with 47 additions and 8 deletions

View file

@ -58,6 +58,10 @@
*even if the set is empty* (in which case it just compares the element
to itself).
#### `dart:developer`
- Added `serverWebSocketUri` property to `ServiceProtocolInfo`.
### Dart VM
### Tools

View file

@ -11,6 +11,7 @@ import 'test_helper.dart';
int? majorVersion;
int? minorVersion;
Uri? serverUri;
Uri? wsServerUri;
Future<Null> testeeBefore() async {
print('testee before');
@ -20,8 +21,8 @@ Future<Null> testeeBefore() async {
ServiceProtocolInfo info = await Service.getInfo();
majorVersion = info.majorVersion;
minorVersion = info.minorVersion;
serverUri = info.serverUri;
Expect.isNull(info.serverUri);
Expect.isNull(info.serverWebSocketUri);
{
// Now, start the web server and store the URI which is expected to be
// non NULL in the top level variable.
@ -30,7 +31,11 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.isNotNull(info.serverUri);
Expect.isNotNull(info.serverWebSocketUri);
serverUri = info.serverUri;
wsServerUri = info.serverWebSocketUri;
Expect.equals(wsServerUri!.scheme, 'ws');
Expect.isTrue(wsServerUri!.path.endsWith('ws'));
}
{
// Now try starting the web server again, this should just return the
@ -39,6 +44,7 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.equals(info.serverUri, serverUri);
Expect.equals(info.serverWebSocketUri, wsServerUri);
}
{
// Try turning off the web server, this should turn off the server and
@ -47,6 +53,7 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.isNull(info.serverUri);
Expect.isNull(info.serverWebSocketUri);
}
{
// Try turning off the web server again, this should be a nop
@ -55,16 +62,17 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.isNull(info.serverUri);
Expect.isNull(info.serverWebSocketUri);
}
{
// Start the web server again for the test below.
ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
majorVersion = info.majorVersion;
minorVersion = info.minorVersion;
serverUri = info.serverUri;
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.equals(info.serverUri, serverUri);
Expect.isNotNull(info.serverUri);
Expect.isNotNull(info.serverWebSocketUri);
}
}

View file

@ -11,6 +11,7 @@ import 'test_helper.dart';
int majorVersion;
int minorVersion;
Uri serverUri;
Uri wsServerUri;
Future<Null> testeeBefore() async {
print('testee before');
@ -20,8 +21,8 @@ Future<Null> testeeBefore() async {
ServiceProtocolInfo info = await Service.getInfo();
majorVersion = info.majorVersion;
minorVersion = info.minorVersion;
serverUri = info.serverUri;
Expect.isNull(info.serverUri);
Expect.isNull(info.serverWebSocketUri);
{
// Now, start the web server and store the URI which is expected to be
// non NULL in the top level variable.
@ -31,6 +32,9 @@ Future<Null> testeeBefore() async {
Expect.equals(info.minorVersion, minorVersion);
Expect.isNotNull(info.serverUri);
serverUri = info.serverUri;
wsServerUri = info.serverWebSocketUri;
Expect.equals(wsServerUri.scheme, 'ws');
Expect.isTrue(wsServerUri.path.endsWith('ws'));
}
{
// Now try starting the web server again, this should just return the
@ -39,6 +43,7 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.equals(info.serverUri, serverUri);
Expect.equals(info.serverWebSocketUri, wsServerUri);
}
{
// Try turning off the web server, this should turn off the server and
@ -47,6 +52,7 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.isNull(info.serverUri);
Expect.isNull(info.serverWebSocketUri);
}
{
// Try turning off the web server again, this should be a nop
@ -55,16 +61,17 @@ Future<Null> testeeBefore() async {
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.isNull(info.serverUri);
Expect.isNull(info.serverWebSocketUri);
}
{
// Start the web server again for the test below.
ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
majorVersion = info.majorVersion;
minorVersion = info.minorVersion;
serverUri = info.serverUri;
Expect.equals(info.majorVersion, majorVersion);
Expect.equals(info.minorVersion, minorVersion);
Expect.equals(info.serverUri, serverUri);
Expect.isNotNull(info.serverUri);
Expect.isNotNull(info.serverWebSocketUri);
}
}

View file

@ -17,10 +17,30 @@ class ServiceProtocolInfo {
/// not support the service protocol, this is 0.
final int minorVersion = _getServiceMinorVersion();
/// The Uri to access the service. If the web server is not running, this
/// will be null.
/// The Uri to connect to the debugger client hosted by the service. If the
/// web server is not running, this will be null.
final Uri? serverUri;
/// The Uri to connect to the service via web socket. If the web server is
/// not running, this will be null.
Uri? get serverWebSocketUri {
Uri? uri = serverUri;
if (uri != null) {
final pathSegments = <String>[];
if (uri.pathSegments.isNotEmpty) {
pathSegments.addAll(uri.pathSegments.where(
// Strip out the empty string that appears at the end of path segments.
// Empty string elements will result in an extra '/' being added to the
// URI.
(s) => s.isNotEmpty,
));
}
pathSegments.add('ws');
uri = uri.replace(scheme: 'ws', pathSegments: pathSegments);
}
return uri;
}
ServiceProtocolInfo(this.serverUri);
String toString() {