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

Side by Side Diff: runtime/observatory/tests/service/async_generator_breakpoint_test.dart

Issue 1143783003: Add the streamListen and streamCancel rpcs to the vm service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: before commit Created 5 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --verbose -debug 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --verbose -debug
5 5
6 import 'package:observatory/service_io.dart'; 6 import 'package:observatory/service_io.dart';
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 import 'dart:async';
8 import 'test_helper.dart'; 9 import 'test_helper.dart';
9 10
10 printSync() { // Line 10 11 printSync() { // Line 11
11 print('sync'); 12 print('sync');
12 } 13 }
13 printAsync() async { // Line 13 14 printAsync() async { // Line 14
14 print('async'); 15 print('async');
15 } 16 }
16 printAsyncStar() async* { // Line 16 17 printAsyncStar() async* { // Line 17
17 print('async*'); 18 print('async*');
18 } 19 }
19 printSyncStar() sync* { // Line 19 20 printSyncStar() sync* { // Line 20
20 print('sync*'); 21 print('sync*');
21 } 22 }
22 23
23 var testerReady = false; 24 var testerReady = false;
24 testeeDo() { 25 testeeDo() {
25 // We block here rather than allowing the isolate to enter the 26 // We block here rather than allowing the isolate to enter the
26 // paused-on-exit state before the tester gets a chance to set 27 // paused-on-exit state before the tester gets a chance to set
27 // the breakpoints because we need the event loop to remain 28 // the breakpoints because we need the event loop to remain
28 // operational for the async bodies to run. 29 // operational for the async bodies to run.
29 print('testee waiting'); 30 print('testee waiting');
30 while(!testerReady); 31 while(!testerReady);
31 32
32 printSync(); 33 printSync();
33 var future = printAsync(); 34 var future = printAsync();
34 var stream = printAsyncStar(); 35 var stream = printAsyncStar();
35 var iterator = printSyncStar(); 36 var iterator = printSyncStar();
36 37
37 print('middle'); // Line 37. 38 print('middle'); // Line 38
38 39
39 future.then((v) => print(v)); 40 future.then((v) => print(v));
40 stream.toList(); 41 stream.toList();
41 iterator.toList(); 42 iterator.toList();
42 } 43 }
43 44
44 testAsync(Isolate isolate) async { 45 testAsync(Isolate isolate) async {
45 await isolate.rootLibrary.load(); 46 await isolate.rootLibrary.load();
46 var script = isolate.rootLibrary.scripts[0]; 47 var script = isolate.rootLibrary.scripts[0];
47 48
48 var bp1 = await isolate.addBreakpoint(script, 10); 49 var bp1 = await isolate.addBreakpoint(script, 11);
49 expect(bp1, isNotNull); 50 expect(bp1, isNotNull);
50 expect(bp1 is Breakpoint, isTrue); 51 expect(bp1 is Breakpoint, isTrue);
51 var bp2 = await isolate.addBreakpoint(script, 13); 52 var bp2 = await isolate.addBreakpoint(script, 14);
52 expect(bp2, isNotNull); 53 expect(bp2, isNotNull);
53 expect(bp2 is Breakpoint, isTrue); 54 expect(bp2 is Breakpoint, isTrue);
54 var bp3 = await isolate.addBreakpoint(script, 16); 55 var bp3 = await isolate.addBreakpoint(script, 17);
55 expect(bp3, isNotNull); 56 expect(bp3, isNotNull);
56 expect(bp3 is Breakpoint, isTrue); 57 expect(bp3 is Breakpoint, isTrue);
57 var bp4 = await isolate.addBreakpoint(script, 19); 58 var bp4 = await isolate.addBreakpoint(script, 20);
58 expect(bp4, isNotNull); 59 expect(bp4, isNotNull);
59 expect(bp4 is Breakpoint, isTrue); 60 expect(bp4 is Breakpoint, isTrue);
60 var bp5 = await isolate.addBreakpoint(script, 37); 61 var bp5 = await isolate.addBreakpoint(script, 38);
61 print("BP5 - $bp5"); 62 print("BP5 - $bp5");
62 expect(bp5, isNotNull); 63 expect(bp5, isNotNull);
63 expect(bp5 is Breakpoint, isTrue); 64 expect(bp5 is Breakpoint, isTrue);
64 65
65 var hits = []; 66 var hits = [];
66 67
67 isolate.rootLibrary.evaluate('testerReady = true;') 68 Completer completer = new Completer();
68 .then((Instance result) { 69 isolate.vm.debugEvents.listen((ServiceEvent event) {
69 expect(result.valueAsString, equals('true'));
70 });
71
72 await for (ServiceEvent event in isolate.vm.events.stream) {
73 if (event.eventType == ServiceEvent.kPauseBreakpoint) { 70 if (event.eventType == ServiceEvent.kPauseBreakpoint) {
74 var bp = event.breakpoint; 71 var bp = event.breakpoint;
75 print('Hit $bp'); 72 print('Hit $bp');
76 hits.add(bp); 73 hits.add(bp);
77 isolate.resume(); 74 isolate.resume();
78 75
79 if (hits.length == 5) break; 76 if (hits.length == 5) {
77 completer.complete();
78 }
80 } 79 }
81 } 80 });
82 81
82 isolate.rootLibrary.evaluate('testerReady = true;')
83 .then((Instance result) {
84 expect(result.valueAsString, equals('true'));
85 });
86
87 await completer.future;
83 expect(hits, equals([bp1, bp5, bp4, bp2, bp3])); 88 expect(hits, equals([bp1, bp5, bp4, bp2, bp3]));
84 } 89 }
85 90
86 var tests = [testAsync]; 91 var tests = [testAsync];
87 92
88 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeDo); 93 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeDo);
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/observatory/tests/service/code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698