Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Unified Diff: runtime/observatory/tests/service/test_helper.dart

Issue 1241673003: Async-step, first cut. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/observatory/tests/service/command_test.dart ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/observatory/tests/service/test_helper.dart
diff --git a/runtime/observatory/tests/service/test_helper.dart b/runtime/observatory/tests/service/test_helper.dart
index 8ff0b253878d157626367658ccfcfb9ce534a2cc..53520c443187ced1eb7e3ab8e7109bdc86e84c42 100644
--- a/runtime/observatory/tests/service/test_helper.dart
+++ b/runtime/observatory/tests/service/test_helper.dart
@@ -9,6 +9,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
bool _isWebSocketDisconnect(e) {
return e is NetworkRpcException;
@@ -155,26 +156,35 @@ Future processServiceEvents(VM vm,
}
-Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) async {
- await isolate.reload(); // Might have missed pauseEvent.
-
- if ((isolate.pauseEvent != null) &&
- (isolate.pauseEvent.kind == ServiceEvent.kPauseBreakpoint)) {
- // Already waiting at a breakpoint.
- print('Breakpoint reached');
- return new Future.value(isolate);
- }
-
+Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) {
// Set up a listener to wait for breakpoint events.
Completer completer = new Completer();
isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
var subscription;
subscription = stream.listen((ServiceEvent event) {
+ print("Event: $event");
if (event.kind == ServiceEvent.kPauseBreakpoint) {
print('Breakpoint reached');
subscription.cancel();
- completer.complete();
+ if (completer != null) {
+ completer.complete(isolate);
+ completer = null;
+ }
+ }
+ });
+
+ // Pause may have happened before we subscribed.
+ isolate.reload().then((_) {
+ if ((isolate.pauseEvent != null) &&
+ (isolate.pauseEvent.kind == ServiceEvent.kPauseBreakpoint)) {
+ // Already waiting at a breakpoint.
+ print('Breakpoint reached');
+ subscription.cancel();
+ if (completer != null) {
+ completer.complete(isolate);
+ completer = null;
}
+ }
});
});
@@ -182,6 +192,35 @@ Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) async {
}
+// Currying is your friend.
+IsolateTest setBreakpointAtLine(int line) {
+ return (Isolate isolate) async {
+ print("Setting breakpoint for line $line");
+ Library lib = await isolate.rootLibrary.load();
+ Script script = lib.scripts.single;
+
+ Breakpoint bpt = await isolate.addBreakpoint(script, line);
+ print("Breakpoint is $bpt");
+ expect(bpt, isNotNull);
+ expect(bpt is Breakpoint, isTrue);
+ };
+}
+
+IsolateTest stoppedAtLine(int line) {
+ return (Isolate isolate) async {
+ print("Checking we are at line $line");
+
+ ServiceMap stack = await isolate.getStack();
+ expect(stack.type, equals('Stack'));
+ expect(stack['frames'].length, greaterThanOrEqualTo(1));
+
+ Frame top = stack['frames'][0];
+ Script script = await top.location.script.load();
+ expect(script.tokenToLine(top.location.tokenPos), equals(line));
+ };
+}
+
+
Future<Isolate> resumeIsolate(Isolate isolate) {
Completer completer = new Completer();
isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
« no previous file with comments | « runtime/observatory/tests/service/command_test.dart ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698