dart-sdk/pkg/dds/test/regress_45569_test.dart
Ben Konyi 4d4f69ab95 Reland "[ package:dds ] Add locking when modifying DDS state via client requests"
This reverts commit 0b0bb9940d.

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

TEST=dds/test/regress_45569_test.dart and service_2/break_on_function_many_child_isolates_test/dds

Change-Id: I84ac047adb7b20a5392744993b22895bffacce9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209262
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Anna Gringauze <annagrin@google.com>
2021-08-07 15:16:49 +00:00

62 lines
1.7 KiB
Dart

// Copyright (c) 2021, 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:io';
import 'dart:math';
import 'package:dds/dds.dart';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import 'common/test_helper.dart';
void main() {
late Process process;
late DartDevelopmentService dds;
setUp(() async {
// We don't care what's actually running in the target process for this
// test, so we're just using an existing one.
process = await spawnDartProcess(
'get_stream_history_script.dart',
pauseOnStart: false,
);
});
tearDown(() async {
await dds.shutdown();
process.kill();
});
Future<void> streamSubscribeUnsubscribe(
VmService client, {
required bool delay,
}) async {
await client.streamListen('Service');
await Future.delayed(
Duration(milliseconds: delay ? Random().nextInt(200) : 0),
);
await client.streamCancel('Service');
}
test('Ensure streamListen and streamCancel calls are handled atomically',
() async {
for (int i = 0; i < 100; ++i) {
dds = await DartDevelopmentService.startDartDevelopmentService(
remoteVmServiceUri,
);
expect(dds.isRunning, true);
final connection1 = await vmServiceConnectUri(dds.wsUri.toString());
final connection2 = await vmServiceConnectUri(dds.wsUri.toString());
await Future.wait([
streamSubscribeUnsubscribe(connection1, delay: true),
streamSubscribeUnsubscribe(connection2, delay: false),
]);
await dds.shutdown();
}
});
}