OLD | NEW |
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 --checked
--verbose-debug | 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked
--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 'test_helper.dart'; | 8 import 'test_helper.dart'; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
11 printSync() { // Line 12 | 11 printSync() { // Line 11 |
12 print('sync'); | 12 print('sync'); |
13 } | 13 } |
14 printAsync() async { // Line 15 | 14 printAsync() async { // Line 14 |
15 print('async'); | 15 print('async'); |
16 } | 16 } |
17 printAsyncStar() async* { // Line 18 | 17 printAsyncStar() async* { // Line 17 |
18 print('async*'); | 18 print('async*'); |
19 } | 19 } |
20 printSyncStar() sync* { // Line 21 | 20 printSyncStar() sync* { // Line 20 |
21 print('sync*'); | 21 print('sync*'); |
22 } | 22 } |
23 | 23 |
24 var testerReady = false; | 24 var testerReady = false; |
25 testeeDo() { | 25 testeeDo() { |
26 // We block here rather than allowing the isolate to enter the | 26 // We block here rather than allowing the isolate to enter the |
27 // 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 |
28 // the breakpoints because we need the event loop to remain | 28 // the breakpoints because we need the event loop to remain |
29 // operational for the async bodies to run. | 29 // operational for the async bodies to run. |
30 print('testee waiting'); | 30 print('testee waiting'); |
31 while(!testerReady); | 31 while(!testerReady); |
32 | 32 |
33 printSync(); | 33 printSync(); |
34 var future = printAsync(); | 34 var future = printAsync(); |
35 var stream = printAsyncStar(); | 35 var stream = printAsyncStar(); |
36 var iterator = printSyncStar(); | 36 var iterator = printSyncStar(); |
37 | 37 |
38 print('middle'); // Line 39. | 38 print('middle'); // Line 38. |
39 | 39 |
40 future.then((v) => print(v)); | 40 future.then((v) => print(v)); |
41 stream.toList(); | 41 stream.toList(); |
42 iterator.toList(); | 42 iterator.toList(); |
43 } | 43 } |
44 | 44 |
45 testAsync(Isolate isolate) async { | 45 testAsync(Isolate isolate) async { |
46 await isolate.rootLib.load(); | 46 await isolate.rootLib.load(); |
47 var script = isolate.rootLib.scripts[0]; | 47 var script = isolate.rootLib.scripts[0]; |
48 | 48 |
49 var bp1 = await isolate.addBreakpoint(script, 12); | 49 var bp1 = await isolate.addBreakpoint(script, 11); |
50 expect(bp1, isNotNull); | 50 expect(bp1, isNotNull); |
51 expect(bp1 is Breakpoint, isTrue); | 51 expect(bp1 is Breakpoint, isTrue); |
52 var bp2 = await isolate.addBreakpoint(script, 15); | 52 var bp2 = await isolate.addBreakpoint(script, 14); |
53 expect(bp2, isNotNull); | 53 expect(bp2, isNotNull); |
54 expect(bp2 is Breakpoint, isTrue); | 54 expect(bp2 is Breakpoint, isTrue); |
55 var bp3 = await isolate.addBreakpoint(script, 18); | 55 var bp3 = await isolate.addBreakpoint(script, 17); |
56 expect(bp3, isNotNull); | 56 expect(bp3, isNotNull); |
57 expect(bp3 is Breakpoint, isTrue); | 57 expect(bp3 is Breakpoint, isTrue); |
58 var bp4 = await isolate.addBreakpoint(script, 21); | 58 var bp4 = await isolate.addBreakpoint(script, 20); |
59 expect(bp4, isNotNull); | 59 expect(bp4, isNotNull); |
60 expect(bp4 is Breakpoint, isTrue); | 60 expect(bp4 is Breakpoint, isTrue); |
61 var bp5 = await isolate.addBreakpoint(script, 39); | 61 var bp5 = await isolate.addBreakpoint(script, 38); |
| 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.eval(isolate.rootLib, 'testerReady = true;') | 68 isolate.eval(isolate.rootLib, 'testerReady = true;') |
68 .then((Instance result) { | 69 .then((Instance result) { |
69 expect(result.valueAsString, equals('true')); | 70 expect(result.valueAsString, equals('true')); |
70 }); | 71 }); |
71 | 72 |
72 await for (ServiceEvent event in isolate.vm.events.stream) { | 73 await for (ServiceEvent event in isolate.vm.events.stream) { |
73 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | 74 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
74 var bp = event.breakpoint; | 75 var bp = event.breakpoint; |
75 print('Hit $bp'); | 76 print('Hit $bp'); |
76 hits.add(bp); | 77 hits.add(bp); |
77 isolate.resume(); | 78 isolate.resume(); |
78 | 79 |
79 if (hits.length == 5) break; | 80 if (hits.length == 5) break; |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 expect(hits, equals([bp1, bp5, bp4, bp2, bp3])); | 84 expect(hits, equals([bp1, bp5, bp4, bp2, bp3])); |
84 } | 85 } |
85 | 86 |
86 var tests = [testAsync]; | 87 var tests = [testAsync]; |
87 | 88 |
88 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeDo); | 89 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeDo); |
OLD | NEW |