Skip to content

Commit ad34b0e

Browse files
kenzieschmollCommit Queue
authored andcommitted
Register the VM service on DTD from DDS
Bug: #60540 Change-Id: Ib646f3bfc0aff079b0cd57dca71e9c3646919eca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429760 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Kenzie Davisson <[email protected]>
1 parent 8a4b95f commit ad34b0e

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

pkg/dds/lib/src/dds_impl.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'dart:typed_data';
1111

1212
import 'package:devtools_shared/devtools_extensions_io.dart';
1313
import 'package:devtools_shared/devtools_shared.dart' show DtdInfo;
14+
import 'package:dtd/dtd.dart' hide RpcErrorCodes;
1415
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
1516
import 'package:meta/meta.dart';
1617
import 'package:shelf/shelf.dart';
@@ -271,6 +272,23 @@ class DartDevelopmentServiceImpl implements DartDevelopmentService {
271272
}
272273

273274
_uri = tmpUri;
275+
276+
// If DDS is hosting the Dart Tooling Daemon, it needs to register the VM
277+
// Service URI on DTD.
278+
final hostedDtd = _hostedDartToolingDaemon;
279+
if (hostedDtd != null && wsUri != null) {
280+
final dtdClient = await DartToolingDaemon.connect(hostedDtd.localUri);
281+
await dtdClient.registerVmService(
282+
uri: wsUri!.toString(),
283+
secret: hostedDtd.secret!,
284+
);
285+
// Immediately close this client after registering the VM service. The
286+
// VM service will be automatically unregistered from DTD when the VM
287+
// service shuts down. For this case, DTD will also be shut down as part
288+
// of shutting down DDS & the VM Service so we do not need to worry about
289+
// unregistering the VM service manually.
290+
await dtdClient.close();
291+
}
274292
}
275293

276294
/// Stop accepting requests after gracefully handling existing requests.

pkg/dds/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies:
1616
collection: ^1.15.0
1717
dds_service_extensions: ^2.0.0
1818
dap: ^1.4.0
19+
dtd: ^3.0.0
1920
extension_discovery: ^2.0.0
2021
devtools_shared: ^11.0.0
2122
http_multi_server: ^3.0.0

pkg/dds/test/client_name_rpc_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import 'common/test_helper.dart';
1010

1111
final tests = <VMTest>[
1212
(VmService service) async {
13-
final defaultClientName = 'client1';
13+
// This will be 'client2' instead of 'client1' because the Dart Tooling
14+
// Daemon that is managed by DDS will connect the first client to this
15+
// VM Service connection.
16+
final defaultClientName = 'client2';
1417
final clientName = 'agent-007';
1518
var result = await service.getClientName();
1619
expect(result.name, defaultClientName);

pkg/dds/test/get_client_name_rpc_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ final test = <IsolateTest>[
1515
// Each client has a default name based on the order of connection to the
1616
// service.
1717
var clientName = await service.getClientName();
18-
expect(clientName.name, 'client1');
18+
19+
// This will be 'client2' instead of 'client1' because the Dart Tooling
20+
// Daemon that is managed by DDS will connect the first client to this
21+
// VM Service connection.
22+
final defaultClientName = 'client2';
23+
24+
expect(clientName.name, defaultClientName);
1925

2026
// Set a custom client name and check it was set properly.
2127
await service.setClientName('foobar');
@@ -25,7 +31,7 @@ final test = <IsolateTest>[
2531
// Clear the client name and check that we're using the default again.
2632
await service.setClientName();
2733
clientName = await service.getClientName();
28-
expect(clientName.name, 'client1');
34+
expect(clientName.name, defaultClientName);
2935
},
3036
];
3137

0 commit comments

Comments
 (0)