Skip to content

Commit

Permalink
Merge branch 'master' into remove-prints
Browse files Browse the repository at this point in the history
  • Loading branch information
elliette authored Mar 26, 2024
2 parents 9142aa9 + 2024775 commit 521893d
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 92 deletions.
7 changes: 5 additions & 2 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## 23.4.0-wip
## 24.0.0-wip

- Rename `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes. - [#2360](https://github.com/dart-lang/webdev/pull/2360)
- Implement `setFlag` when it is called with `pause_isolates_on_start`. - [#2373](https://github.com/dart-lang/webdev/pull/2373)
- Do not persist breakpoints across hot restarts or page reloads. - [#2371](https://github.com/dart-lang/webdev/pull/2371)
- If `pause_isolates_on_start` is `true`, wait for `resume` to run the app's `main` method. - [#2378](https://github.com/dart-lang/webdev/pull/2378)

**Breaking changes**

- Rename `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes. - [#2360](https://github.com/dart-lang/webdev/pull/2360)

## 23.3.0

- Filter out internal type properties from the new DDC type system. - [#2348](https://github.com/dart-lang/webdev/pull/2348)
Expand Down
5 changes: 5 additions & 0 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,11 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
return _rpcNotSupportedFuture('getVMTimelineMicros');
}

@override
Future<void> yieldControlToDDS(String uri) async {
// TODO(elliette): implement
}

@override
Future<InboundReferences> getInboundReferences(
String isolateId,
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dwds
# Every time this changes you need to run `dart run build_runner build`.
version: 23.4.0-wip
version: 24.0.0-wip
description: >-
A service that proxies between the Chrome debug protocol and the Dart VM
service protocol.
Expand Down Expand Up @@ -33,8 +33,8 @@ dependencies:
stack_trace: ^1.10.0
sse: ^4.1.2
uuid: ^3.0.6
vm_service: ">=13.0.0 <15.0.0"
vm_service_interface: 1.0.1
vm_service: ^14.0.0
vm_service_interface: 1.1.0
web_socket_channel: ^2.2.0
webkit_inspection_protocol: ^1.0.1

Expand Down
22 changes: 18 additions & 4 deletions dwds/test/chrome_proxy_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2064,22 +2064,34 @@ void main() {
});

group('setFlag', () {
test('pause_isolates_on_start set to true', () {
test('pause_isolates_on_start set to true', () async {
final service = context.service;
expect(
service.setFlag('pause_isolates_on_start', 'true'),
completion(_isSuccess),
);
expect(context.dwds!.shouldPauseIsolatesOnStart, equals(true));
// Re-try until sucess because the value doesn't get updated
// synchronously (it is sent over a stream):
final pauseIsolatesOnStart = await retryFn(
() => context.dwds!.shouldPauseIsolatesOnStart,
expectedResult: true,
);
expect(pauseIsolatesOnStart, equals(true));
});

test('pause_isolates_on_start set to false', () {
test('pause_isolates_on_start set to false', () async {
final service = context.service;
expect(
service.setFlag('pause_isolates_on_start', 'false'),
completion(_isSuccess),
);
expect(context.dwds!.shouldPauseIsolatesOnStart, equals(false));
// Re-try until sucess because the value doesn't get updated
// synchronously (it is sent over a stream):
final pauseIsolatesOnStart = await retryFn(
() => context.dwds!.shouldPauseIsolatesOnStart,
expectedResult: false,
);
expect(pauseIsolatesOnStart, equals(false));
});

test('pause_isolates_on_start set to invalid value', () {
Expand Down Expand Up @@ -2444,3 +2456,5 @@ final _isSuccess = isA<Success>();

TypeMatcher _libRef(uriMatcher) =>
isA<LibraryRef>().having((l) => l.uri, 'uri', uriMatcher);

void expectEventually(Matcher expectation) {}
166 changes: 88 additions & 78 deletions dwds/test/debug_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,83 +47,93 @@ void main() {
);
});

test('Refuses additional connections when in single client mode', () async {
final ddsWs = await WebSocket.connect(
'${context.debugConnection.uri}/ws',
);
final completer = Completer<void>();
ddsWs.listen((event) {
final response = json.decode(event as String);
test(
'Refuses additional connections when in single client mode',
() async {
final ddsWs = await WebSocket.connect(
'${context.debugConnection.uri}/ws',
);
final completer = Completer<void>();
ddsWs.listen((event) {
final response = json.decode(event as String);
expect(response['id'], '0');
expect(response.containsKey('result'), isTrue);
final result = response['result'] as Map<String, dynamic>;
expect(result['type'], 'Success');
completer.complete();
});

const yieldControlToDDS = <String, dynamic>{
'jsonrpc': '2.0',
'id': '0',
'method': '_yieldControlToDDS',
'params': {
'uri': 'http://localhost:123',
},
};
ddsWs.add(json.encode(yieldControlToDDS));
await completer.future;

// While DDS is connected, expect additional connections to fail.
await expectLater(
WebSocket.connect('${context.debugConnection.uri}/ws'),
throwsA(isA<WebSocketException>()),
);

// However, once DDS is disconnected, additional clients can connect again.
await ddsWs.close();
expect(
WebSocket.connect('${context.debugConnection.uri}/ws')
.then((ws) => ws.close()),
completes,
);
},
// TODO(elliette): Re-enable test.
skip: true,
);

test(
'Refuses to yield to dwds if existing clients found',
() async {
final ddsWs = await WebSocket.connect(
'${context.debugConnection.uri}/ws',
);

// Connect to vm service.
final ws = await WebSocket.connect('${context.debugConnection.uri}/ws');

final completer = Completer<Map<String, dynamic>>();
ddsWs.listen((event) {
completer.complete(json.decode(event as String));
});

const yieldControlToDDS = <String, dynamic>{
'jsonrpc': '2.0',
'id': '0',
'method': '_yieldControlToDDS',
'params': {
'uri': 'http://localhost:123',
},
};

// DDS should fail to start with existing vm clients.
ddsWs.add(json.encode(yieldControlToDDS));

final response = await completer.future;
expect(response['id'], '0');
expect(response.containsKey('result'), isTrue);
final result = response['result'] as Map<String, dynamic>;
expect(result['type'], 'Success');
completer.complete();
});

const yieldControlToDDS = <String, dynamic>{
'jsonrpc': '2.0',
'id': '0',
'method': '_yieldControlToDDS',
'params': {
'uri': 'http://localhost:123',
},
};
ddsWs.add(json.encode(yieldControlToDDS));
await completer.future;

// While DDS is connected, expect additional connections to fail.
await expectLater(
WebSocket.connect('${context.debugConnection.uri}/ws'),
throwsA(isA<WebSocketException>()),
);

// However, once DDS is disconnected, additional clients can connect again.
await ddsWs.close();
expect(
WebSocket.connect('${context.debugConnection.uri}/ws')
.then((ws) => ws.close()),
completes,
);
});

test('Refuses to yield to dwds if existing clients found', () async {
final ddsWs = await WebSocket.connect(
'${context.debugConnection.uri}/ws',
);

// Connect to vm service.
final ws = await WebSocket.connect('${context.debugConnection.uri}/ws');

final completer = Completer<Map<String, dynamic>>();
ddsWs.listen((event) {
completer.complete(json.decode(event as String));
});

const yieldControlToDDS = <String, dynamic>{
'jsonrpc': '2.0',
'id': '0',
'method': '_yieldControlToDDS',
'params': {
'uri': 'http://localhost:123',
},
};

// DDS should fail to start with existing vm clients.
ddsWs.add(json.encode(yieldControlToDDS));

final response = await completer.future;
expect(response['id'], '0');
expect(response.containsKey('error'), isTrue);

final result = response['error'] as Map<String, dynamic>;
expect(result['message'], 'Feature is disabled.');
expect(
result['data'],
'Existing VM service clients prevent DDS from taking control.',
);

await ddsWs.close();
await ws.close();
});
expect(response.containsKey('error'), isTrue);

final result = response['error'] as Map<String, dynamic>;
expect(result['message'], 'Feature is disabled.');
expect(
result['data'],
'Existing VM service clients prevent DDS from taking control.',
);

await ddsWs.close();
await ws.close();
},
// TODO(elliette): Re-enable test.
skip: true,
);
}
7 changes: 5 additions & 2 deletions dwds/test/fixtures/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ int daemonPort(String workingDirectory) {
String _assetServerPortFilePath(String workingDirectory) =>
'${daemonWorkspace(workingDirectory)}/.asset_server_port';

/// Retries a callback function with a delay until the result is non-null.
/// Retries a callback function with a delay until the result is the
/// [expectedResult] (if provided) or is not null.
Future<T> retryFn<T>(
T Function() callback, {
int retryCount = 3,
int delayInMs = 1000,
String failureMessage = 'Function did not succeed after retries.',
T? expectedResult,
}) async {
if (retryCount == 0) {
throw Exception(failureMessage);
Expand All @@ -56,7 +58,8 @@ Future<T> retryFn<T>(
await Future.delayed(Duration(milliseconds: delayInMs));
try {
final result = callback();
if (result != null) return result;
if (expectedResult != null && result == expectedResult) return result;
if (expectedResult == null && result != null) return result;
} catch (_) {
// Ignore any exceptions.
}
Expand Down
3 changes: 2 additions & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ dependencies:
shelf_static: ^1.1.0
stack_trace: ^1.10.0
sse: ^4.1.0
vm_service: ">=10.1.0 <15.0.0"
vm_service: ^14.0.0
vm_service_interface: 1.1.0
webkit_inspection_protocol: ^1.0.1
yaml: ^3.1.1

Expand Down
4 changes: 3 additions & 1 deletion webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ void main() {

await checkProcessStdout(process, [
'webdev could not run for this project.',
'Could not find a file named "pubspec.yaml"'
// TODO(https://github.com/dart-lang/webdev/issues/2393): Uncomment
// this line:
// 'Found no `pubspec.yaml` file',
]);
await process.shouldExit(78);
});
Expand Down

0 comments on commit 521893d

Please sign in to comment.