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

[dwds] Add unbatching retry mechanism for failing batched expression evals #2552

Merged
merged 3 commits into from
Dec 20, 2024
Merged
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 dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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),[#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)

## 24.2.0

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',
});
Loading