| 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 print('Resuming...'); |
| 23 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | |
| 24 var subscription; | |
| 25 subscription = stream.listen((ServiceEvent event) { | |
| 26 if (event.kind == ServiceEvent.kPauseStart) { | |
| 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) { | |
| 49 receivedInterrupt = true; | |
| 50 subscription.cancel(); | |
| 51 completer.complete(); | |
| 52 } | |
| 53 }); | |
| 54 | |
| 55 await isolate.resume(); | 28 await isolate.resume(); |
| 56 | 29 |
| 57 // Wait for the isolate to become idle. We detect this by querying | 30 // Wait for the isolate to become idle. We detect this by querying |
| 58 // the stack until it becomes empty. | 31 // the stack until it becomes empty. |
| 59 var frameCount; | 32 var frameCount; |
| 60 do { | 33 do { |
| 61 var stack = await isolate.getStack(); | 34 var stack = await isolate.getStack(); |
| 62 frameCount = stack['frames'].length; | 35 frameCount = stack['frames'].length; |
| 63 print('frames: $frameCount'); | 36 print('Frames: $frameCount'); |
| 64 sleep(const Duration(milliseconds:10)); | 37 sleep(const Duration(milliseconds:10)); |
| 65 } while (frameCount > 0); | 38 } while (frameCount > 0); |
| 39 print('Isolate is idle.'); |
| 40 await isolate.reload(); |
| 41 expect(isolate.pauseEvent.kind, equals(ServiceEvent.kResume)); |
| 66 | 42 |
| 67 // Make sure that the isolate receives an interrupt even when it is | 43 // Make sure that the isolate receives an interrupt even when it is |
| 68 // idle. (https://github.com/dart-lang/sdk/issues/24349) | 44 // idle. (https://github.com/dart-lang/sdk/issues/24349) |
| 45 var interruptFuture = hasPausedFor(isolate, ServiceEvent.kPauseInterrupted); |
| 46 print('Pausing...'); |
| 69 await isolate.pause(); | 47 await isolate.pause(); |
| 70 await completer.future; | 48 await interruptFuture; |
| 71 expect(receivedInterrupt, isTrue); | |
| 72 }, | 49 }, |
| 73 | 50 |
| 74 ]; | 51 ]; |
| 75 | 52 |
| 76 main(args) => runIsolateTests(args, tests, | 53 main(args) => runIsolateTests(args, tests, |
| 77 testeeConcurrent: testMain, | 54 testeeConcurrent: testMain, |
| 78 pause_on_start: true, | |
| 79 trace_service: true, | 55 trace_service: true, |
| 80 verbose_vm: true); | 56 verbose_vm: true); |
| OLD | NEW |