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=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'dart:async'; | |
7 import 'dart:developer'; | |
8 import 'dart:io'; | |
9 import 'dart:isolate' show ReceivePort; | |
6 import 'package:observatory/service_io.dart'; | 10 import 'package:observatory/service_io.dart'; |
7 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
12 import 'service_test_common.dart'; | |
8 import 'test_helper.dart'; | 13 import 'test_helper.dart'; |
9 import 'dart:async'; | |
10 import 'dart:io'; | |
11 import 'dart:isolate' show ReceivePort; | |
12 | 14 |
13 var receivePort; | 15 var receivePort; |
14 | 16 |
15 void testMain() { | 17 void testMain() { |
16 receivePort = new ReceivePort(); | 18 receivePort = new ReceivePort(); |
19 debugger(); | |
17 } | 20 } |
18 | 21 |
19 var tests = [ | 22 var tests = [ |
20 | 23 |
24 hasStoppedAtBreakpoint, | |
25 | |
21 (Isolate isolate) async { | 26 (Isolate isolate) async { |
22 Completer completer = new Completer(); | 27 // Wait for the isolate to pause due to interruption. |
28 var completer = new Completer(); | |
23 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 29 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
30 bool receivedInterrupt = false; | |
24 var subscription; | 31 var subscription; |
25 subscription = stream.listen((ServiceEvent event) { | 32 subscription = stream.listen((ServiceEvent event) { |
Cutch
2016/03/02 17:42:16
Can this code be replaced with hasPausedFor ?
| |
26 if (event.kind == ServiceEvent.kPauseStart) { | 33 print('Event: $event'); |
27 print('Received $event'); | |
28 subscription.cancel(); | |
29 completer.complete(); | |
30 } | |
31 }); | |
32 | |
33 if (isolate.pauseEvent != null && | |
34 isolate.pauseEvent.kind == ServiceEvent.kPauseStart) { | |
35 // Wait for the isolate to hit PauseStart. | |
36 subscription.cancel(); | |
37 } else { | |
38 await completer.future; | |
39 } | |
40 print('Done waiting for pause event.'); | |
41 | |
42 // Wait for the isolate to pause due to interruption. | |
43 completer = new Completer(); | |
44 stream = await isolate.vm.getEventStream(VM.kDebugStream); | |
45 bool receivedInterrupt = false; | |
46 subscription = stream.listen((ServiceEvent event) { | |
47 print('Received $event'); | |
48 if (event.kind == ServiceEvent.kPauseInterrupted) { | 34 if (event.kind == ServiceEvent.kPauseInterrupted) { |
35 print('Received interrupt.'); | |
49 receivedInterrupt = true; | 36 receivedInterrupt = true; |
50 subscription.cancel(); | 37 subscription.cancel(); |
51 completer.complete(); | 38 completer.complete(); |
52 } | 39 } |
53 }); | 40 }); |
54 | 41 |
42 print('Resuming...'); | |
55 await isolate.resume(); | 43 await isolate.resume(); |
56 | 44 |
57 // Wait for the isolate to become idle. We detect this by querying | 45 // Wait for the isolate to become idle. We detect this by querying |
58 // the stack until it becomes empty. | 46 // the stack until it becomes empty. |
59 var frameCount; | 47 var frameCount; |
60 do { | 48 do { |
61 var stack = await isolate.getStack(); | 49 var stack = await isolate.getStack(); |
62 frameCount = stack['frames'].length; | 50 frameCount = stack['frames'].length; |
63 print('frames: $frameCount'); | 51 print('Frames: $frameCount'); |
64 sleep(const Duration(milliseconds:10)); | 52 sleep(const Duration(milliseconds:10)); |
65 } while (frameCount > 0); | 53 } while (frameCount > 0); |
54 print('Isolate is idle.'); | |
66 | 55 |
67 // Make sure that the isolate receives an interrupt even when it is | 56 // Make sure that the isolate receives an interrupt even when it is |
68 // idle. (https://github.com/dart-lang/sdk/issues/24349) | 57 // idle. (https://github.com/dart-lang/sdk/issues/24349) |
58 print('Pausing...'); | |
69 await isolate.pause(); | 59 await isolate.pause(); |
70 await completer.future; | 60 await completer.future; |
71 expect(receivedInterrupt, isTrue); | 61 expect(receivedInterrupt, isTrue); |
72 }, | 62 }, |
73 | 63 |
74 ]; | 64 ]; |
75 | 65 |
76 main(args) => runIsolateTests(args, tests, | 66 main(args) => runIsolateTests(args, tests, |
77 testeeConcurrent: testMain, | 67 testeeConcurrent: testMain, |
78 pause_on_start: true, | |
79 trace_service: true, | 68 trace_service: true, |
80 verbose_vm: true); | 69 verbose_vm: true); |
OLD | NEW |