Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dev tools URL when debugging #2283

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Increase SDK constraint to ^3.5.0-311.0.dev.
* Support running Node.js tests compiled with dart2wasm.
* Allow `firefox` or `firefox-bin` executable name on macOS.
* Use a DevTools URL instead of a defunct observatory URL.

## 1.25.8

Expand Down
1 change: 1 addition & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fix dart2wasm tests on windows.
* Increase SDK constraint to ^3.5.0-311.0.dev.
* Allow passing additional arguments to `dart compile wasm`.
* Use a DevTools URL instead of a defunct observatory URL.

## 0.6.5

Expand Down
5 changes: 3 additions & 2 deletions pkgs/test_core/lib/src/runner/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ abstract class Environment {
/// Whether this environment supports interactive debugging.
bool get supportsDebugging;

/// The URL of the Dart VM Observatory for this environment, or `null` if this
/// environment doesn't run the Dart VM or the URL couldn't be detected.
/// The URL of the Dart Dev Tools server for this environment, or `null` if
/// this environment doesn't run the Dart VM or the URL couldn't be detected.
// TODO(https://github.com/dart-lang/test/issues/2185) rename to `devToolsUrl`
Uri? get observatoryUrl;

/// The URL of the remote debugger for this environment, or `null` if it isn't
Expand Down
39 changes: 20 additions & 19 deletions pkgs/test_core/lib/src/runner/vm/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class VMPlatform extends PlatformPlugin {

Environment? environment;
IsolateRef? isolateRef;
String? isolateID;
Uri? serverUri;
if (_config.debug) {
if (platform.compiler == Compiler.exe) {
throw UnsupportedError(
Expand All @@ -115,29 +117,25 @@ class VMPlatform extends PlatformPlugin {
}
var info =
await Service.controlWebServer(enable: true, silenceOutput: true);
// ignore: deprecated_member_use, Remove when SDK constraint is at 3.2.0
var isolateID = Service.getIsolateID(isolate!)!;
serverUri = info.serverUri!;
isolateID = Service.getIsolateId(isolate!)!;

var libraryPath = (await absoluteUri(path)).toString();
var serverUri = info.serverUri!;
client = await vmServiceConnectUri(_wsUriFor(serverUri).toString());
var serviceWebsocket = _wsUriFor(serverUri);
client = await vmServiceConnectUri(serviceWebsocket.toString());
var isolateNumber = int.parse(isolateID.split('/').last);
isolateRef = (await client.getVM())
.isolates!
.firstWhere((isolate) => isolate.number == isolateNumber.toString());
await client.setName(isolateRef.id!, path);
var libraryRef = (await client.getIsolate(isolateRef.id!))
.libraries!
.firstWhere((library) => library.uri == libraryPath);
var url = _observatoryUrlFor(serverUri, isolateRef.id!, libraryRef.id!);
var url = _devtoolsUriFor(serviceWebsocket);
environment = VMEnvironment(url, isolateRef, client);
}

environment ??= const PluginEnvironment();

var controller = deserializeSuite(
path, platform, suiteConfig, environment, channel.cast(), message,
gatherCoverage: () => _gatherCoverage(environment!));
gatherCoverage: () => _gatherCoverage(serverUri!, isolateID!));

if (isolateRef != null) {
await client!.streamListen('Debug');
Expand Down Expand Up @@ -331,20 +329,23 @@ stderr: ${processResult.stderr}''');
}
}

Future<Map<String, dynamic>> _gatherCoverage(Environment environment) async {
final isolateId = Uri.parse(environment.observatoryUrl!.fragment)
.queryParameters['isolateId'];
return await collect(environment.observatoryUrl!, false, false, false, {},
isolateIds: {isolateId!});
Future<Map<String, dynamic>> _gatherCoverage(
Uri serviceUri, String isolateId) async {
return await collect(serviceUri, false, false, false, {},
isolateIds: {isolateId});
}

Uri _wsUriFor(Uri observatoryUrl) =>
observatoryUrl.replace(scheme: 'ws').resolve('ws');

Uri _observatoryUrlFor(Uri base, String isolateId, String id) => base.replace(
fragment: Uri(
path: '/inspect',
queryParameters: {'isolateId': isolateId, 'objectId': id}).toString());
Uri _devtoolsUriFor(Uri serviceUri) {
assert(serviceUri.isScheme('ws'));
return serviceUri.resolve('devtools/debugger').replace(
scheme: 'http',
queryParameters: {'uri': '$serviceUri'},
fragment: '',
);
}

var _hasRegistered = false;
void _setupPauseAfterTests() {
Expand Down
Loading