OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'test_helper.dart'; | 6 import 'test_helper.dart'; |
7 import 'service_test_common.dart'; | 7 import 'service_test_common.dart'; |
8 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 | 10 |
11 const int LINE_A = 28, LINE_B = 33; | 11 const int LINE_A = 28, LINE_B = 33; |
12 | 12 |
13 class VMServiceClient { | 13 class VMServiceClient { |
14 VMServiceClient(this.x); | 14 VMServiceClient(this.x); |
15 close() => new Future.microtask(() => print("close")); | 15 close() => new Future.microtask(() => print("close")); |
16 var x; | 16 var x; |
17 } | 17 } |
18 | 18 |
19 collect() async { | 19 collect() async { |
20 var uri = "abc"; | 20 var uri = "abc"; |
21 var vmService; | 21 var vmService; |
22 await new Future.microtask(() async { | 22 await new Future.microtask(() async { |
23 try { | 23 try { |
24 vmService = new VMServiceClient(uri); | 24 vmService = new VMServiceClient(uri); |
25 await new Future.microtask(() => throw new TimeoutException("here")); | 25 await new Future.microtask(() => throw new TimeoutException("here")); |
26 } on dynamic { | 26 } on dynamic { |
27 vmService.close(); | 27 vmService.close(); |
28 rethrow; // LINE_A | 28 rethrow; // LINE_A |
29 } | 29 } |
30 }); | 30 }); |
31 } | 31 } |
32 | 32 |
33 test_code() async { // LINE_B | 33 test_code() async { |
| 34 // LINE_B |
34 try { | 35 try { |
35 await collect(); | 36 await collect(); |
36 } on TimeoutException { | 37 } on TimeoutException { |
37 print("ok"); | 38 print("ok"); |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 Future<Isolate> stepThroughProgram(Isolate isolate) async { | 42 Future<Isolate> stepThroughProgram(Isolate isolate) async { |
42 Completer completer = new Completer(); | 43 Completer completer = new Completer(); |
43 int pauseEventsSeen = 0; | 44 int pauseEventsSeen = 0; |
44 | 45 |
45 await subscribeToStream(isolate.vm, VM.kDebugStream, | 46 await subscribeToStream(isolate.vm, VM.kDebugStream, |
46 (ServiceEvent event) async { | 47 (ServiceEvent event) async { |
47 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 48 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
48 // We are paused: Step further. | 49 // We are paused: Step further. |
49 pauseEventsSeen++; | 50 pauseEventsSeen++; |
50 isolate.stepInto(); | 51 isolate.stepInto(); |
51 } else if (event.kind == ServiceEvent.kPauseExit) { | 52 } else if (event.kind == ServiceEvent.kPauseExit) { |
52 // We are at the exit: The test is done. | 53 // We are at the exit: The test is done. |
53 expect(pauseEventsSeen > 20, true, | 54 expect(pauseEventsSeen > 20, true, |
54 reason: "Saw only $pauseEventsSeen pause events."); | 55 reason: "Saw only $pauseEventsSeen pause events."); |
55 await cancelStreamSubscription(VM.kDebugStream); | 56 await cancelStreamSubscription(VM.kDebugStream); |
56 completer.complete(); | 57 completer.complete(); |
57 } | 58 } |
58 }); | 59 }); |
59 isolate.resume(); | 60 isolate.resume(); |
60 return completer.future; | 61 return completer.future; |
61 } | 62 } |
62 | 63 |
63 var tests = [hasPausedAtStart, | 64 var tests = [ |
64 markDartColonLibrariesDebuggable, | 65 hasPausedAtStart, |
65 setBreakpointAtLine(LINE_B), | 66 markDartColonLibrariesDebuggable, |
66 resumeIsolate, | 67 setBreakpointAtLine(LINE_B), |
67 hasStoppedAtBreakpoint, | 68 resumeIsolate, |
68 setBreakpointAtLine(LINE_A), | 69 hasStoppedAtBreakpoint, |
69 resumeIsolate, | 70 setBreakpointAtLine(LINE_A), |
70 hasStoppedAtBreakpoint, | 71 resumeIsolate, |
71 stepOut, | 72 hasStoppedAtBreakpoint, |
72 stoppedAtLine(LINE_B), | 73 stepOut, |
73 resumeIsolate]; | 74 stoppedAtLine(LINE_B), |
| 75 resumeIsolate |
| 76 ]; |
74 | 77 |
75 main(args) => runIsolateTestsSynchronous(args, tests, | 78 main(args) => runIsolateTestsSynchronous(args, tests, |
76 testeeConcurrent: test_code, pause_on_start: true, pause_on_exit: false); | 79 testeeConcurrent: test_code, pause_on_start: true, pause_on_exit: false); |
OLD | NEW |