| 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 '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 import 'dart:io'; |
| 11 import 'dart:isolate'; |
| 12 |
| 13 var receivePort; |
| 10 | 14 |
| 11 void testMain() { | 15 void testMain() { |
| 12 print('Hello'); | 16 receivePort = new ReceivePort(); |
| 13 } | 17 } |
| 14 | 18 |
| 15 var tests = [ | 19 var tests = [ |
| 16 | 20 |
| 17 (Isolate isolate) async { | 21 (Isolate isolate) async { |
| 18 print('Getting stream...'); | |
| 19 Completer completer = new Completer(); | 22 Completer completer = new Completer(); |
| 20 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 23 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 21 print('Subscribing...'); | |
| 22 var subscription; | 24 var subscription; |
| 23 subscription = stream.listen((ServiceEvent event) { | 25 subscription = stream.listen((ServiceEvent event) { |
| 24 if (event.kind == ServiceEvent.kPauseStart) { | 26 if (event.kind == ServiceEvent.kPauseStart) { |
| 25 print('Received $event'); | 27 print('Received $event'); |
| 26 subscription.cancel(); | 28 subscription.cancel(); |
| 27 completer.complete(); | 29 completer.complete(); |
| 28 } else { | |
| 29 print('Ignoring event $event'); | |
| 30 } | 30 } |
| 31 }); | 31 }); |
| 32 print('Subscribed. Pause event is ${isolate.pauseEvent}'); | |
| 33 | 32 |
| 34 if (isolate.pauseEvent != null && | 33 if (isolate.pauseEvent != null && |
| 35 isolate.pauseEvent.kind == ServiceEvent.kPauseStart) { | 34 isolate.pauseEvent.kind == ServiceEvent.kPauseStart) { |
| 36 // Wait for the isolate to hit PauseStart. | 35 // Wait for the isolate to hit PauseStart. |
| 37 subscription.cancel(); | 36 subscription.cancel(); |
| 38 print('Subscription cancelled.'); | |
| 39 } else { | 37 } else { |
| 40 print('Waiting for pause start event.'); | |
| 41 await completer.future; | 38 await completer.future; |
| 42 } | 39 } |
| 43 print('Done waiting for pause event.'); | 40 print('Done waiting for pause event.'); |
| 44 | 41 |
| 45 // Grab the timestamp. | 42 // Wait for the isolate to pause due to interruption. |
| 46 var pausetime1 = isolate.pauseEvent.timestamp; | |
| 47 expect(pausetime1, isNotNull); | |
| 48 // Reload the isolate. | |
| 49 await isolate.reload(); | |
| 50 // Verify that it is the same. | |
| 51 expect(pausetime1.millisecondsSinceEpoch, | |
| 52 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); | |
| 53 | |
| 54 completer = new Completer(); | 43 completer = new Completer(); |
| 55 stream = await isolate.vm.getEventStream(VM.kDebugStream); | 44 stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 45 bool receivedInterrupt = false; |
| 56 subscription = stream.listen((ServiceEvent event) { | 46 subscription = stream.listen((ServiceEvent event) { |
| 57 if (event.kind == ServiceEvent.kPauseExit) { | 47 print('Received $event'); |
| 58 print('Received PauseExit'); | 48 if (event.kind == ServiceEvent.kPauseInterrupted) { |
| 49 receivedInterrupt = true; |
| 59 subscription.cancel(); | 50 subscription.cancel(); |
| 60 completer.complete(); | 51 completer.complete(); |
| 61 } | 52 } |
| 62 }); | 53 }); |
| 63 | 54 |
| 64 print('Resuming...'); | 55 await isolate.resume(); |
| 65 isolate.resume(); | |
| 66 | 56 |
| 67 // Wait for the isolate to hit PauseExit. | 57 // Wait for the isolate to become idle. We detect this by querying |
| 58 // the stack until it becomes empty. |
| 59 var frameCount; |
| 60 do { |
| 61 var stack = await isolate.getStack(); |
| 62 frameCount = stack['frames'].length; |
| 63 print('frames: $frameCount'); |
| 64 sleep(const Duration(milliseconds:10)); |
| 65 } while (frameCount > 0); |
| 66 |
| 67 // Make sure that the isolate receives an interrupt even when it is |
| 68 // idle. (https://github.com/dart-lang/sdk/issues/24349) |
| 69 await isolate.pause(); |
| 68 await completer.future; | 70 await completer.future; |
| 69 | 71 expect(receivedInterrupt, isTrue); |
| 70 // Grab the timestamp. | |
| 71 var pausetime2 = isolate.pauseEvent.timestamp; | |
| 72 expect(pausetime2, isNotNull); | |
| 73 // Reload the isolate. | |
| 74 await isolate.reload(); | |
| 75 // Verify that it is the same. | |
| 76 expect(pausetime2.millisecondsSinceEpoch, | |
| 77 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); | |
| 78 expect(pausetime2.millisecondsSinceEpoch, | |
| 79 greaterThan(pausetime1.millisecondsSinceEpoch)); | |
| 80 }, | 72 }, |
| 81 | 73 |
| 82 ]; | 74 ]; |
| 83 | 75 |
| 84 main(args) => runIsolateTests(args, tests, | 76 main(args) => runIsolateTests(args, tests, |
| 85 testeeConcurrent: testMain, | 77 testeeConcurrent: testMain, |
| 86 pause_on_start: true, | 78 pause_on_start: true, |
| 87 pause_on_exit: true, | |
| 88 trace_service: true, | 79 trace_service: true, |
| 89 verbose_vm: true); | 80 verbose_vm: true); |
| OLD | NEW |