Files
sdk/pkg/dds/test/dds_disconnects_existing_clients_test.dart
Ben Konyi ae1b83869a [ Service ] Add support for DDS to package:dart_runtime_service_vm
The DartRuntimeService based VM service implementation now has support
for launching DDS instances and responding to _yieldControlToDDS RPC
invocations from DDS instances.

package:vm_service test suite is ~97% passing with this change.

TEST=Local testing.
Change-Id: I2f2f1b0926845134578f08d073ed7606f1fc4173
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490320
Reviewed-by: Jessy Yameogo <yjessy@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2026-04-10 12:04:28 -07:00

61 lines
2.0 KiB
Dart

// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:dds/dds.dart';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'common/test_helper.dart';
final tests = <VMTest>[
(VmService service) async {
late DartDevelopmentService dds;
final waitForDDS = Completer<void>();
final serviceMessageCompleter = Completer<void>();
// A service event is sent to all existing clients when DDS connects before
// their connection is closed.
service.onServiceEvent.listen((event) async {
// Wait for dds to be set before checking the server's URI.
await waitForDDS.future;
final message =
'A Dart Developer Service instance has connected and this direct '
'connection to the VM service will now be closed. Please reconnect to '
'the Dart Development Service at ${dds.uri}.';
expect(event.kind, 'DartDevelopmentServiceConnected');
expect(event.json!['message'], message);
expect(event.json!['uri'], dds.uri.toString());
serviceMessageCompleter.complete();
});
await service.streamListen(EventStreams.kService);
// Start DDS, which should result in the original VM service client being
// disconnected from the VM service.
final remote = Uri.parse(service.wsUri!);
dds = await DartDevelopmentService.startDartDevelopmentService(
remote.replace(
scheme: 'http',
pathSegments: remote.pathSegments.sublist(
0,
remote.pathSegments.length - 1,
),
),
);
waitForDDS.complete();
expect(dds.isRunning, true);
await serviceMessageCompleter.future;
await service.onDone;
await dds.shutdown();
}
];
void main([args = const <String>[]]) => runVMTests(
args,
tests,
'dds_disconnects_existing_clients_test.dart',
extraArgs: ['--no-dds'],
);