OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'dart:async'; |
| 7 import 'dart:developer'; |
| 8 import 'dart:io'; |
| 9 import 'package:observatory/service_io.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'test_helper.dart'; |
| 12 |
| 13 int count = 0; |
| 14 |
| 15 void test() { |
| 16 while (true) { |
| 17 count++; |
| 18 debugger(); |
| 19 } |
| 20 } |
| 21 |
| 22 var tests = [ |
| 23 hasStoppedAtBreakpoint, |
| 24 |
| 25 (Isolate isolate) async { |
| 26 // The loop has run one time. |
| 27 var result = await isolate.rootLibrary.evaluate('count'); |
| 28 expect(result.type, equals('Instance')); |
| 29 expect(result.valueAsString, equals('1')); |
| 30 |
| 31 Completer completer = new Completer(); |
| 32 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 33 var subscription; |
| 34 subscription = stream.listen((ServiceEvent event) { |
| 35 if (event.kind == ServiceEvent.kResume) { |
| 36 subscription.cancel(); |
| 37 completer.complete(); |
| 38 } |
| 39 }); |
| 40 isolate.resume(); |
| 41 await completer.future; |
| 42 |
| 43 // The loop has run twice. |
| 44 result = await isolate.rootLibrary.evaluate('count'); |
| 45 expect(result.type, equals('Instance')); |
| 46 expect(result.valueAsString, equals('2')); |
| 47 }, |
| 48 |
| 49 hasStoppedAtBreakpoint, |
| 50 |
| 51 (Isolate isolate) async { |
| 52 Isolate newIsolate = null; |
| 53 |
| 54 Completer testCompleter = new Completer(); |
| 55 var debugStream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 56 var debugSub; |
| 57 debugSub = debugStream.listen((ServiceEvent event) { |
| 58 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 59 if (event.isolate == newIsolate) { |
| 60 // The old isolate has died and the new isolate is at |
| 61 // the breakpoint. |
| 62 newIsolate.reload().then((_) { |
| 63 newIsolate.rootLibrary.evaluate('count').then((result) { |
| 64 expect(result.type, equals('Instance')); |
| 65 expect(result.valueAsString, equals('1')); |
| 66 debugSub.cancel(); |
| 67 testCompleter.complete(); |
| 68 }); |
| 69 }); |
| 70 } |
| 71 } |
| 72 }); |
| 73 |
| 74 Completer restartCompleter = new Completer(); |
| 75 var isolateStream = await isolate.vm.getEventStream(VM.kIsolateStream); |
| 76 var isolateSub; |
| 77 bool exit = false; |
| 78 bool start = false; |
| 79 isolateSub = isolateStream.listen((ServiceEvent event) { |
| 80 if (event.kind == ServiceEvent.kIsolateExit) { |
| 81 expect(event.isolate, equals(isolate)); |
| 82 print('Old isolate exited'); |
| 83 exit = true; |
| 84 } |
| 85 if (event.kind == ServiceEvent.kIsolateStart) { |
| 86 print('New isolate started'); |
| 87 newIsolate = event.isolate; |
| 88 start = true; |
| 89 } |
| 90 if (exit && start) { |
| 91 isolateSub.cancel(); |
| 92 restartCompleter.complete(); |
| 93 } |
| 94 }); |
| 95 |
| 96 // Restart the vm. |
| 97 print("restarting"); |
| 98 await isolate.vm.restart(); |
| 99 await restartCompleter.future; |
| 100 print("restarted"); |
| 101 await testCompleter.future; |
| 102 }, |
| 103 ]; |
| 104 |
| 105 |
| 106 main(args) => runIsolateTests(args, tests, testeeConcurrent: test); |
OLD | NEW |