Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into dwds2421
Browse files Browse the repository at this point in the history
  • Loading branch information
srujzs committed Dec 23, 2024
2 parents cfef5fe + 3684897 commit ee7d193
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Update to be forward compatible with changes to `package:shelf_web_socket`.
- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537)
- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537),[#2544](https://github.com/dart-lang/webdev/issues/2544)
- Fix issue where batched expression evals were failing if any subexpression failed. - [#2551](https://github.com/dart-lang/webdev/issues/2551)
- Expose a partial implementation of
`FrontendServerDdcLibraryBundleStrategyProvider`.
- Update `package:vm_service_interface` to '^2.0.1'.
Expand Down
53 changes: 26 additions & 27 deletions dwds/lib/src/services/batched_expression_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,38 +134,37 @@ class BatchedExpressionEvaluator extends ExpressionEvaluator {
first.scope,
);

final listId = list.objectId;
if (listId == null) {
for (final request in requests) {
safeUnawaited(_evaluateBatch([request]));
}
return;
}

for (var i = 0; i < requests.length; i++) {
final request = requests[i];
if (request.completer.isCompleted) continue;
_logger.fine('Getting result out of a batch for ${request.expression}');

final listId = list.objectId;
if (listId == null) {
final error = createError(
EvaluationErrorKind.internal,
'No batch result object ID.',
);
request.completer.complete(error);
} else {
safeUnawaited(
_inspector
.getProperties(
listId,
offset: i,
count: 1,
length: requests.length,
)
.then((v) {
final result = v.first.value!;
_logger.fine(
'Got result out of a batch for ${request.expression}: $result',
);
request.completer.complete(result);
}),
onError: (error, stackTrace) =>
request.completer.completeError(error, stackTrace),
);
}
safeUnawaited(
_inspector
.getProperties(
listId,
offset: i,
count: 1,
length: requests.length,
)
.then((v) {
final result = v.first.value!;
_logger.fine(
'Got result out of a batch for ${request.expression}: $result',
);
request.completer.complete(result);
}),
onError: (error, stackTrace) =>
request.completer.completeError(error, stackTrace),
);
}
}
}
20 changes: 18 additions & 2 deletions dwds/test/expression_evaluator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:dwds/src/debugging/location.dart';
import 'package:dwds/src/debugging/skip_list.dart';
import 'package:dwds/src/services/batched_expression_evaluator.dart';
import 'package:dwds/src/services/expression_evaluator.dart';
import 'package:dwds/src/utilities/shared.dart';

import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart' hide LogRecord;
Expand All @@ -36,6 +37,7 @@ void main() async {

late StreamController<DebuggerPausedEvent> pausedController;
late StreamController<Event> debugEventController;
late FakeInspector inspector;
setUp(() async {
final assetReader = FakeAssetReader(sourceMap: '');
final toolConfiguration = TestToolConfiguration.withLoadStrategy(
Expand Down Expand Up @@ -64,8 +66,7 @@ void main() async {
skipLists,
root,
);
final inspector =
FakeInspector(webkitDebugger, fakeIsolate: simpleIsolate);
inspector = FakeInspector(webkitDebugger, fakeIsolate: simpleIsolate);
debugger.updateInspector(inspector);

_evaluator = ExpressionEvaluator(
Expand Down Expand Up @@ -192,6 +193,21 @@ void main() async {
);
});

test('retries failed batched expression', () async {
safeUnawaited(
evaluator.evaluateExpression('2', 'main.dart', 'true', {}),
);

await evaluator.evaluateExpression('2', 'main.dart', 'false', {});
expect(inspector.functionsCalled.length, 3);
expect(
inspector.functionsCalled[0].contains('return [ true, false ];'),
true,
);
expect(inspector.functionsCalled[1].contains('return true;'), true);
expect(inspector.functionsCalled[2].contains('return false;'), true);
});

test('returns error if closed', () async {
evaluator.close();
final result =
Expand Down
11 changes: 9 additions & 2 deletions dwds/test/fixtures/fakes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Isolate get simpleIsolate => Isolate(

class FakeInspector implements AppInspector {
final WebkitDebugger _remoteDebugger;
final List<String> functionsCalled = [];
FakeInspector(this._remoteDebugger, {required this.fakeIsolate});

Isolate fakeIsolate;
Expand All @@ -61,8 +62,10 @@ class FakeInspector implements AppInspector {
Future<RemoteObject> callFunction(
String function,
Iterable<String> argumentIds,
) async =>
RemoteObject({'type': 'string', 'value': 'true'});
) async {
functionsCalled.add(function);
return RemoteObject({'type': 'string', 'value': 'true'});
}

@override
Future<void> initialize() async => {};
Expand Down Expand Up @@ -473,3 +476,7 @@ final fakeWipResponse = WipResponse({
'id': 1,
'result': {'fake': ''},
});

final fakeFailingWipResponse = WipResponse({
'result': 'Error: Bad request',
});

0 comments on commit ee7d193

Please sign in to comment.