| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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'; | 6 import 'dart:async'; |
| 7 import 'dart:developer'; | 7 import 'dart:developer'; |
| 8 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import 'service_test_common.dart'; | 10 import 'service_test_common.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 dart.Isolate.spawn(isolate, receive.sendPort); | 31 dart.Isolate.spawn(isolate, receive.sendPort); |
| 32 } | 32 } |
| 33 | 33 |
| 34 var tests = [ | 34 var tests = [ |
| 35 hasPausedAtStart, | 35 hasPausedAtStart, |
| 36 (Isolate isolate) async { | 36 (Isolate isolate) async { |
| 37 int step = 0; | 37 int step = 0; |
| 38 var completer = new Completer(); | 38 var completer = new Completer(); |
| 39 var sub; | 39 var sub; |
| 40 final Isolate firstIsolate = isolate; | 40 final Isolate firstIsolate = isolate; |
| 41 print("First isolate is: ${firstIsolate.id}"); |
| 41 Isolate secondIsolate; | 42 Isolate secondIsolate; |
| 42 sub = await isolate.vm.listenEventStream(VM.kDebugStream, (ServiceEvent c) { | 43 sub = await isolate.vm.listenEventStream(VM.kDebugStream, (ServiceEvent c) { |
| 44 print("Event ${c.kind} on ${c.isolate.id}"); |
| 43 switch (step) { | 45 switch (step) { |
| 44 case 0: | 46 case 0: |
| 45 expect(c.kind, equals("Resume"), | 47 expect(c.kind, equals(ServiceEvent.kResume), |
| 46 reason: "First isolate should resume"); | 48 reason: "First isolate should resume"); |
| 47 expect(c.isolate.id, equals(firstIsolate.id), | 49 expect(c.isolate.id, equals(firstIsolate.id), |
| 48 reason: "First isolate should resume"); | 50 reason: "First isolate should resume"); |
| 49 break; | 51 break; |
| 50 case 1: | 52 case 1: |
| 51 expect(c.kind, equals("PauseStart"), | 53 expect(c.kind, equals(ServiceEvent.kPauseStart), |
| 52 reason: "Second isolate should pause on start"); | 54 reason: "Second isolate should pause on start"); |
| 53 expect(c.isolate.id, equals(isolate.vm.isolates[1].id), | 55 expect(c.isolate.id, equals(isolate.vm.isolates[1].id), |
| 54 reason: "Second isolate should pause on start"); | 56 reason: "Second isolate should pause on start"); |
| 55 secondIsolate = c.isolate; | 57 secondIsolate = c.isolate; |
| 58 print("Second isolate is: ${secondIsolate.id}"); |
| 59 print("Resuming second isolate"); |
| 56 secondIsolate.resume(); | 60 secondIsolate.resume(); |
| 57 break; | 61 break; |
| 58 case 2: | 62 case 2: |
| 59 expect(c.kind, equals("Resume"), | 63 expect(c.kind, equals(ServiceEvent.kResume), |
| 60 reason: "Second isolate should resume"); | 64 reason: "Second isolate should resume"); |
| 61 expect(c.isolate.id, equals(secondIsolate.id), | 65 expect(c.isolate.id, equals(secondIsolate.id), |
| 62 reason: "Second isolate should resume"); | 66 reason: "Second isolate should resume"); |
| 63 break; | 67 break; |
| 64 case 3: | 68 case 3: |
| 65 expect(c.kind, equals("PauseBreakpoint"), | 69 expect(c.kind, equals(ServiceEvent.kPauseBreakpoint), |
| 66 reason: "First isolate should stop at debugger()"); | 70 reason: "First isolate should stop at debugger()"); |
| 67 expect(c.isolate.id, equals(firstIsolate.id), | 71 expect(c.isolate.id, equals(firstIsolate.id), |
| 68 reason: "First isolate should stop at debugger()"); | 72 reason: "First isolate should stop at debugger()"); |
| 73 print("Resuming first isolate"); |
| 69 firstIsolate.resume(); | 74 firstIsolate.resume(); |
| 70 break; | 75 break; |
| 71 case 4: | 76 case 4: |
| 72 expect(c.kind, equals("Resume"), | 77 expect(c.kind, equals(ServiceEvent.kResume), |
| 73 reason: "First isolate should resume (1)"); | 78 reason: "First isolate should resume (1)"); |
| 74 expect(c.isolate.id, equals(firstIsolate.id), | 79 expect(c.isolate.id, equals(firstIsolate.id), |
| 75 reason: "First isolate should resume (1)"); | 80 reason: "First isolate should resume (1)"); |
| 76 break; | 81 break; |
| 77 case 5: | 82 case 5: |
| 78 expect(c.kind, equals("PauseBreakpoint"), | 83 expect(c.kind, equals(ServiceEvent.kPauseBreakpoint), |
| 79 reason: "First & Second isolate should stop at debugger()"); | 84 reason: "First & Second isolate should stop at debugger()"); |
| 80 break; | 85 break; |
| 81 case 6: | 86 case 6: |
| 82 expect(c.kind, equals("PauseBreakpoint"), | 87 expect(c.kind, equals(ServiceEvent.kPauseBreakpoint), |
| 83 reason: "First & Second isolate should stop at debugger()"); | 88 reason: "First & Second isolate should stop at debugger()"); |
| 89 print("Resuming second isolate"); |
| 84 secondIsolate.resume(); | 90 secondIsolate.resume(); |
| 85 break; | 91 break; |
| 86 case 7: | 92 case 7: |
| 87 expect(c.kind, equals("Resume"), | 93 expect(c.kind, equals(ServiceEvent.kResume), |
| 88 reason: "Second isolate should resume before the exception"); | 94 reason: "Second isolate should resume before the exception"); |
| 89 expect(c.isolate.id, equals(secondIsolate.id), | 95 expect(c.isolate.id, equals(secondIsolate.id), |
| 90 reason: "Second isolate should resume before the exception"); | 96 reason: "Second isolate should resume before the exception"); |
| 91 break; | 97 break; |
| 92 case 8: | 98 case 8: |
| 93 expect(c.kind, equals("PauseExit"), | 99 expect(c.kind, equals(ServiceEvent.kPauseExit), |
| 94 reason: "Second isolate should exit at the exception"); | 100 reason: "Second isolate should exit at the exception"); |
| 95 expect(c.isolate.id, equals(secondIsolate.id), | 101 expect(c.isolate.id, equals(secondIsolate.id), |
| 96 reason: "Second isolate should exit at the exception"); | 102 reason: "Second isolate should exit at the exception"); |
| 97 firstIsolate.resume(); | 103 firstIsolate.resume(); |
| 104 print("Resuming first isolate"); |
| 98 break; | 105 break; |
| 99 case 9: | 106 case 9: |
| 100 expect(c.kind, equals("Resume"), | 107 expect(c.kind, equals(ServiceEvent.kResume), |
| 101 reason: "First isolate should resume after the exception"); | 108 reason: "First isolate should resume after the exception"); |
| 102 expect(c.isolate.id, equals(firstIsolate.id), | 109 expect(c.isolate.id, equals(firstIsolate.id), |
| 103 reason: "First isolate should resume after the exception"); | 110 reason: "First isolate should resume after the exception"); |
| 104 break; | 111 break; |
| 105 case 10: | 112 case 10: |
| 106 expect(c.kind, equals("PauseBreakpoint"), | 113 expect(c.kind, equals(ServiceEvent.kPauseBreakpoint), |
| 107 reason: "First isolate " | 114 reason: "First isolate " |
| 108 "should stop at debugger() after exception.\n" | 115 "should stop at debugger() after exception.\n" |
| 109 "Probably the second resumed even though it was not expect " | 116 "Probably the second resumed even though it was not expect " |
| 110 "to do it."); | 117 "to do it."); |
| 111 expect(c.isolate.id, equals(firstIsolate.id), | 118 expect(c.isolate.id, equals(firstIsolate.id), |
| 112 reason: "First " | 119 reason: "First " |
| 113 "isolate should stop at debugger() after exception.\n" | 120 "isolate should stop at debugger() after exception.\n" |
| 114 "Probably the second resumed even though it was not expect " | 121 "Probably the second resumed even though it was not expect " |
| 115 "to do it."); | 122 "to do it."); |
| 116 completer.complete(); | 123 completer.complete(); |
| 117 break; | 124 break; |
| 118 default: | 125 default: |
| 119 fail("Shouldn't get here, the second isolate resumed even though it " | 126 fail("Shouldn't get here, the second isolate resumed even though it " |
| 120 "was not expect to do it"); | 127 "was not expect to do it"); |
| 121 break; | 128 break; |
| 122 } | 129 } |
| 123 step++; | 130 step++; |
| 124 }); | 131 }); |
| 132 print("Resuming first isolate"); |
| 125 firstIsolate.resume(); | 133 firstIsolate.resume(); |
| 126 await completer.future; | 134 await completer.future; |
| 127 // We wait 1 second to account for delays in the service protocol. | 135 // We wait 1 second to account for delays in the service protocol. |
| 128 // A late message can still arrive. | 136 // A late message can still arrive. |
| 129 await new Future.delayed(const Duration(seconds: 1)); | 137 await new Future.delayed(const Duration(seconds: 1)); |
| 130 // No fails, tear down the stream. | 138 // No fails, tear down the stream. |
| 131 sub.cancel(); | 139 sub.cancel(); |
| 132 } | 140 } |
| 133 ]; | 141 ]; |
| 134 | 142 |
| 135 main(args) async => runIsolateTests(args, tests, | 143 main(args) async => runIsolateTests(args, tests, |
| 136 pause_on_start: true, pause_on_exit: true, testeeConcurrent: test); | 144 pause_on_start: true, pause_on_exit: true, testeeConcurrent: test); |
| OLD | NEW |