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

Unified Diff: runtime/observatory/tests/service/async_step_test.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
Index: runtime/observatory/tests/service/async_step_test.dart
diff --git a/runtime/observatory/tests/service/async_step_test.dart b/runtime/observatory/tests/service/async_step_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..43a44e75b3296a5b18561c7163f720cd933418b7
--- /dev/null
+++ b/runtime/observatory/tests/service/async_step_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// VMOptions=--compile_all --error_on_bad_type --error_on_bad_override --verbose_debug
+
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+import 'test_helper.dart';
+import 'dart:developer';
+
+foo() async { }
+
+doAsync(stop) async {
+ if (stop) debugger();
+ await foo(); // Line 15.
+ await foo(); // Line 16.
+ await foo(); // Line 17.
+ return null;
+}
+
+testMain() {
+ // With two runs of doAsync floating around, async step should only cause
+ // us to stop in the run we started in.
+ doAsync(false);
+ doAsync(true);
+}
+
+
+asyncStep(Isolate isolate) async {
+ var event = isolate.pauseEvent;
+ expect(event, isNotNull);
+
+ // 1. Set breakpoint for the continuation and resume the isolate.
+ Instance continuation = event.asyncContinuation;
+ print("Async continuation is $continuation");
+ expect(continuation.isClosure, isTrue);
+
+ var bpt = await isolate.addBreakOnActivation(continuation);
+ expect(bpt is Breakpoint, isTrue);
+ print("Async step to $bpt");
+
+ print("A");
+ await isolate.resume();
+ print("AA");
+ await hasStoppedAtBreakpoint(isolate);
+
+ // 2. Step past the state-machine dispatch.
+ print("AAA");
+ await isolate.stepOver();
+ print("AAAA");
+ await hasStoppedAtBreakpoint(isolate);
+}
+
+// Currying is your friend.
+atLine(int line) {
Cutch 2015/07/15 17:04:23 Add a return type 'IsolateTest': IsolateTest atLi
rmacnak 2015/07/16 19:42:17 Done.
+ return (Isolate isolate) async {
+ ServiceMap stack = await isolate.getStack();
+ expect(stack.type, equals('Stack'));
+ expect(stack['frames'].length, greaterThanOrEqualTo(1));
+
+ Script script = stack['frames'][0].location.script;
+ await script.load();
+ expect(script.tokenToLine(stack['frames'][0].location.tokenPos),
+ equals(line));
+ };
+}
+
+
+var tests = [
+ hasStoppedAtBreakpoint,
+ atLine(15),
+ asyncStep,
+ atLine(16),
+ asyncStep,
+ atLine(17),
+ resumeIsolate,
+];
+
+main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain);

Powered by Google App Engine
This is Rietveld 408576698