dart-sdk/pkg/vm_service/test/get_flag_list_rpc_test.dart
Ben Konyi fa8ea6dfaa [ package:vm_service ] Update tests to be compatible with pub run test
Will allow for tests to be enabled in google3 as pub or portions of pub
are used to run VM tests.

Previously the test harness was configured to look for a URI with a data: scheme to determine if it was being run via pub run test (pub generates its own harness and spawns the test from that). We were parsing the test URI out of this data URI, which wouldn't work correctly in google3.

This change assumes that if Platform.script.scheme == 'data', the test is being run via pub from the root directory of the package. In that case, we can assume there is a 'test' directory and simply use 'test/$scriptName'as the path for the testee process.

TEST=N/A

Change-Id: I589605ebc7001adc9d8595ca8347c0af329b9c28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184541
Reviewed-by: Gary Roumanis <grouma@google.com>
2021-02-12 07:12:54 +00:00

80 lines
2.6 KiB
Dart

// Copyright (c) 2019, 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:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'common/test_helper.dart';
Future getFlagValue(VmService service, String flagName) async {
final result = await service.getFlagList();
final flags = result.flags!;
for (final flag in flags) {
if (flag.name == flagName) {
return flag.valueAsString;
}
}
}
var tests = <VMTest>[
// Modify a flag which does not exist.
(VmService service) async {
final Error result =
(await service.setFlag('does_not_exist', 'true')) as Error;
expect(result.message, 'Cannot set flag: flag not found');
},
// Modify a flag with the wrong value type.
(VmService service) async {
final Error result = (await service.setFlag(
'pause_isolates_on_start', 'not-boolean')) as Error;
expect(result.message, equals('Cannot set flag: invalid value'));
},
// Modify a flag with the right value type.
(VmService service) async {
final result = await service.setFlag('pause_isolates_on_start', 'false');
expect(result, TypeMatcher<Success>());
},
// Modify a flag which cannot be set at runtime.
(VmService service) async {
final Error result = (await service.setFlag('random_seed', '42')) as Error;
expect(result.message, 'Cannot set flag: cannot change at runtime');
},
// Modify the profile_period at runtime.
(VmService service) async {
final kProfilePeriod = 'profile_period';
final kValue = 100;
expect(await getFlagValue(service, kProfilePeriod), '1000');
final completer = Completer();
final stream = await service.onVMEvent;
late var subscription;
subscription = stream.listen((Event event) {
print(event);
if (event.kind == EventKind.kVMFlagUpdate) {
expect(event.flag, kProfilePeriod);
expect(event.newValue, kValue.toString());
subscription.cancel();
completer.complete();
}
});
await service.streamListen(EventStreams.kVM);
final result = await service.setFlag(kProfilePeriod, kValue.toString());
expect(result, TypeMatcher<Success>());
await completer.future;
expect(await getFlagValue(service, kProfilePeriod), kValue.toString());
await service.streamCancel(EventStreams.kVM);
}
];
main([args = const <String>[]]) async => runVMTests(
args,
tests,
'get_flag_list_rpc_test.dart',
);