| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // VMOptions=--error_on_bad_type --error_on_bad_override | |
| 5 | |
| 6 import 'dart:async'; | |
| 7 import 'dart:developer'; | |
| 8 import 'package:observatory/models.dart' as M; | |
| 9 import 'package:observatory/service_io.dart'; | |
| 10 import 'package:unittest/unittest.dart'; | |
| 11 import 'test_helper.dart'; | |
| 12 | |
| 13 import "dart:isolate" as dart; | |
| 14 | |
| 15 void isolate(dart.SendPort port) { | |
| 16 dart.RawReceivePort receive = new dart.RawReceivePort((_) { | |
| 17 debugger(); | |
| 18 throw new Exception(); | |
| 19 }); | |
| 20 port.send(receive.sendPort); | |
| 21 } | |
| 22 | |
| 23 void test() { | |
| 24 dart.RawReceivePort receive = new dart.RawReceivePort((port) { | |
| 25 debugger(); | |
| 26 port.send(null); | |
| 27 debugger(); | |
| 28 port.send(null); | |
| 29 debugger(); | |
| 30 }); | |
| 31 dart.Isolate.spawn(isolate, receive.sendPort); | |
| 32 } | |
| 33 | |
| 34 var tests = [ | |
| 35 (VM vm) async { | |
| 36 await vm.load(); | |
| 37 int step = 0; | |
| 38 var completer = new Completer(); | |
| 39 var sub; | |
| 40 sub = await vm.listenEventStream("Debug", (ServiceEvent c) { | |
| 41 switch (step) { | |
| 42 case 0: | |
| 43 if (c.kind == "PauseStart") { | |
| 44 // We have intercepted the first isolate pause on start. | |
| 45 // So the isolate was loading during initialization. | |
| 46 // We will resume here. | |
| 47 vm.isolates[0].resume(); | |
| 48 return; | |
| 49 } | |
| 50 expect(c.kind, equals("Resume"), | |
| 51 reason: "First isolate should resume"); | |
| 52 expect(c.isolate.id, equals(vm.isolates[0].id), | |
| 53 reason: "First isolate should resume"); | |
| 54 break; | |
| 55 case 1: | |
| 56 expect(c.kind, equals("PauseStart"), | |
| 57 reason: "Second isolate should pause on start"); | |
| 58 expect(c.isolate.id, equals(vm.isolates[1].id), | |
| 59 reason: "Second isolate should pause on start"); | |
| 60 vm.isolates[1].resume(); | |
| 61 break; | |
| 62 case 2: | |
| 63 expect(c.kind, equals("Resume"), | |
| 64 reason: "Second isolate should resume"); | |
| 65 expect(c.isolate.id, equals(vm.isolates[1].id), | |
| 66 reason: "Second isolate should resume"); | |
| 67 break; | |
| 68 case 3: | |
| 69 expect(c.kind, equals("PauseBreakpoint"), | |
| 70 reason: "First isolate should stop at debugger()"); | |
| 71 expect(c.isolate.id, equals(vm.isolates[0].id), | |
| 72 reason: "First isolate should stop at debugger()"); | |
| 73 vm.isolates[0].resume(); | |
| 74 break; | |
| 75 case 4: | |
| 76 expect(c.kind, equals("Resume"), | |
| 77 reason: "First isolate should resume (1)"); | |
| 78 expect(c.isolate.id, equals(vm.isolates[0].id), | |
| 79 reason: "First isolate should resume (1)"); | |
| 80 break; | |
| 81 case 5: | |
| 82 expect(c.kind, equals("PauseBreakpoint"), | |
| 83 reason: "First & Second isolate should stop at debugger()"); | |
| 84 break; | |
| 85 case 6: | |
| 86 expect(c.kind, equals("PauseBreakpoint"), | |
| 87 reason: "First & Second isolate should stop at debugger()"); | |
| 88 vm.isolates[1].resume(); | |
| 89 break; | |
| 90 case 7: | |
| 91 expect(c.kind, equals("Resume"), | |
| 92 reason: "Second isolate should resume before the exception"); | |
| 93 expect(c.isolate.id, equals(vm.isolates[1].id), | |
| 94 reason: "Second isolate should resume before the exception"); | |
| 95 break; | |
| 96 case 8: | |
| 97 expect(c.kind, equals("PauseExit"), | |
| 98 reason: "Second isolate should exit at the exception"); | |
| 99 expect(c.isolate.id, equals(vm.isolates[1].id), | |
| 100 reason: "Second isolate should exit at the exception"); | |
| 101 vm.isolates[0].resume(); | |
| 102 break; | |
| 103 case 9: | |
| 104 expect(c.kind, equals("Resume"), | |
| 105 reason: "First isolate should resume after the exception"); | |
| 106 expect(c.isolate.id, equals(vm.isolates[0].id), | |
| 107 reason: "First isolate should resume after the exception"); | |
| 108 break; | |
| 109 case 10: | |
| 110 expect(c.kind, equals("PauseBreakpoint"), | |
| 111 reason: "First isolate " | |
| 112 "should stop at debugger() after exception.\n" | |
| 113 "Probably the second resumed even though it was not expect " | |
| 114 "to do it."); | |
| 115 expect(c.isolate.id, equals(vm.isolates[0].id), | |
| 116 reason: "First " | |
| 117 "isolate should stop at debugger() after exception.\n" | |
| 118 "Probably the second resumed even though it was not expect " | |
| 119 "to do it."); | |
| 120 completer.complete(); | |
| 121 break; | |
| 122 default: | |
| 123 expect(false, isTrue, | |
| 124 reason: "Shouldn't get here, the second " | |
| 125 "isolate resumed even though it was not expect to do it"); | |
| 126 break; | |
| 127 } | |
| 128 step++; | |
| 129 }); | |
| 130 switch (vm.isolates[0].status) { | |
| 131 case M.IsolateStatus.loading: | |
| 132 // It is still loading we will resume in the stream listener. | |
| 133 break; | |
| 134 case M.IsolateStatus.paused: | |
| 135 // It is already paused we will resume here. | |
| 136 vm.isolates[0].resume(); | |
| 137 break; | |
| 138 default: | |
| 139 expect(false, isTrue, | |
| 140 reason: "The first isolate should be loading or paused on start"); | |
| 141 } | |
| 142 await completer.future; | |
| 143 // We wait 1 second to account for delays in the service protocol. | |
| 144 // A late message can still arrive. | |
| 145 await new Future.delayed(const Duration(seconds: 1)); | |
| 146 // No fails, tear down the stream. | |
| 147 sub.cancel(); | |
| 148 } | |
| 149 ]; | |
| 150 | |
| 151 main(args) async => runVMTests(args, tests, | |
| 152 pause_on_start: true, pause_on_exit: true, testeeConcurrent: test); | |
| OLD | NEW |