Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: runtime/observatory/tests/service/isolate_lifecycle_test.dart

Issue 2759973004: Fix observatory tests broken by running dartfmt. Temporarily reverted formatting for evaluate_activ… (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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'; 6 import 'dart:async';
7 import 'dart:developer'; 7 import 'dart:developer';
8 import 'dart:isolate' as I; 8 import 'dart:isolate' as I;
9 9
10 import 'package:observatory/service_io.dart'; 10 import 'package:observatory/service_io.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 import 'service_test_common.dart'; 12 import 'service_test_common.dart';
13 import 'test_helper.dart'; 13 import 'test_helper.dart';
14 14
15 final spawnCount = 4; 15 final spawnCount = 4;
16 final resumeCount = spawnCount ~/ 2; 16 final resumeCount = spawnCount ~/ 2;
17 final isolates = []; 17 final isolates = [];
18 18
19 void spawnEntry(int i) { 19 void spawnEntry(int i) {}
20 }
21 20
22 Future during() async { 21 Future during() async {
23 debugger(); 22 debugger();
24 // Spawn spawnCount long lived isolates. 23 // Spawn spawnCount long lived isolates.
25 for (var i = 0; i < spawnCount; i++) { 24 for (var i = 0; i < spawnCount; i++) {
26 var isolate = await I.Isolate.spawn(spawnEntry, i); 25 var isolate = await I.Isolate.spawn(spawnEntry, i);
27 isolates.add(isolate); 26 isolates.add(isolate);
28 } 27 }
29 print('spawned all isolates'); 28 print('spawned all isolates');
30 } 29 }
31 30
32 int numPaused(vm) { 31 int numPaused(vm) {
33 int paused = 0; 32 int paused = 0;
34 for (var isolate in vm.isolates) { 33 for (var isolate in vm.isolates) {
35 if (isolate.paused) { 34 if (isolate.paused) {
36 paused++; 35 paused++;
37 } 36 }
38 } 37 }
39 return paused; 38 return paused;
40 } 39 }
41 40
42 var tests = [ 41 var tests = [
43 (VM vm) async { 42 (VM vm) async {
44 expect(vm.isolates.length, 1); 43 expect(vm.isolates.length, 1);
45 await hasStoppedAtBreakpoint(vm.isolates[0]); 44 await hasStoppedAtBreakpoint(vm.isolates[0]);
46 }, 45 },
47
48 (VM vm) async { 46 (VM vm) async {
49 Completer completer = new Completer(); 47 Completer completer = new Completer();
50 var stream = await vm.getEventStream(VM.kIsolateStream); 48 var stream = await vm.getEventStream(VM.kIsolateStream);
51 var subscription; 49 var subscription;
52 int startCount = 0; 50 int startCount = 0;
53 int runnableCount = 0; 51 int runnableCount = 0;
54 subscription = stream.listen((ServiceEvent event) { 52 subscription = stream.listen((ServiceEvent event) {
55 if (event.kind == ServiceEvent.kIsolateStart) { 53 if (event.kind == ServiceEvent.kIsolateStart) {
56 startCount++; 54 startCount++;
57 } 55 }
58 if (event.kind == ServiceEvent.kIsolateRunnable) { 56 if (event.kind == ServiceEvent.kIsolateRunnable) {
59 runnableCount++; 57 runnableCount++;
60 } 58 }
61 if (runnableCount == spawnCount) { 59 if (runnableCount == spawnCount) {
62 subscription.cancel(); 60 subscription.cancel();
63 completer.complete(null); 61 completer.complete(null);
64 } 62 }
65 }); 63 });
66 expect(vm.isolates.length, 1); 64 expect(vm.isolates.length, 1);
67 vm.isolates[0].resume(); 65 vm.isolates[0].resume();
68 await completer.future; 66 await completer.future;
69 expect(startCount, spawnCount); 67 expect(startCount, spawnCount);
70 expect(runnableCount, spawnCount); 68 expect(runnableCount, spawnCount);
71 expect(vm.isolates.length, spawnCount + 1); 69 expect(vm.isolates.length, spawnCount + 1);
72 }, 70 },
73
74 (VM vm) async { 71 (VM vm) async {
75 // Load each isolate. 72 // Load each isolate.
76 for (var isolate in vm.isolates) { 73 for (var isolate in vm.isolates) {
77 await isolate.load(); 74 await isolate.load();
78 } 75 }
79 }, 76 },
80
81 (VM vm) async { 77 (VM vm) async {
82 Completer completer = new Completer(); 78 Completer completer = new Completer();
83 var stream = await vm.getEventStream(VM.kDebugStream); 79 var stream = await vm.getEventStream(VM.kDebugStream);
84 if (numPaused(vm) < (spawnCount + 1)) { 80 if (numPaused(vm) < (spawnCount + 1)) {
85 var subscription; 81 var subscription;
86 subscription = stream.listen((ServiceEvent event) { 82 subscription = stream.listen((ServiceEvent event) {
87 if (event.kind == ServiceEvent.kPauseExit) { 83 if (event.kind == ServiceEvent.kPauseExit) {
88 if (numPaused(vm) == (spawnCount + 1)) { 84 if (numPaused(vm) == (spawnCount + 1)) {
89 subscription.cancel(); 85 subscription.cancel();
90 completer.complete(null); 86 completer.complete(null);
91 } 87 }
92 } 88 }
93 }); 89 });
94 await completer.future; 90 await completer.future;
95 } 91 }
96 expect(numPaused(vm), spawnCount + 1); 92 expect(numPaused(vm), spawnCount + 1);
97 }, 93 },
98
99
100 (VM vm) async { 94 (VM vm) async {
101 var resumedReceived = 0; 95 var resumedReceived = 0;
102 Completer completer = new Completer(); 96 Completer completer = new Completer();
103 var stream = await vm.getEventStream(VM.kIsolateStream); 97 var stream = await vm.getEventStream(VM.kIsolateStream);
104 var subscription; 98 var subscription;
105 subscription = stream.listen((ServiceEvent event) { 99 subscription = stream.listen((ServiceEvent event) {
106 if (event.kind == ServiceEvent.kIsolateExit) { 100 if (event.kind == ServiceEvent.kIsolateExit) {
107 resumedReceived++; 101 resumedReceived++;
108 if (resumedReceived >= resumeCount) { 102 if (resumedReceived >= resumeCount) {
109 subscription.cancel(); 103 subscription.cancel();
110 completer.complete(null); 104 completer.complete(null);
111 } 105 }
112 } 106 }
113 }); 107 });
114 108
115 // Resume a subset of the isolates. 109 // Resume a subset of the isolates.
116 var resumesIssued = 0; 110 var resumesIssued = 0;
117 var isolateList = vm.isolates.toList(); 111 var isolateList = vm.isolates.toList();
118 for (var isolate in isolateList) { 112 for (var isolate in isolateList) {
119 if (isolate.name.endsWith('main')) { 113 if (isolate.name.endsWith('main')) {
120 continue; 114 continue;
121 } 115 }
122 try { 116 try {
123 resumesIssued++; 117 resumesIssued++;
124 await isolate.resume(); 118 await isolate.resume();
125 } catch(_) {} 119 } catch (_) {}
126 if (resumesIssued == resumeCount) { 120 if (resumesIssued == resumeCount) {
127 break; 121 break;
128 } 122 }
129 } 123 }
130 await completer.future; 124 await completer.future;
131 }, 125 },
132
133 (VM vm) async { 126 (VM vm) async {
134 expect(numPaused(vm), spawnCount + 1 - resumeCount); 127 expect(numPaused(vm), spawnCount + 1 - resumeCount);
135 }, 128 },
136 ]; 129 ];
137 130
138 main(args) async => runVMTests(args, tests, 131 main(args) async =>
139 testeeConcurrent: during, 132 runVMTests(args, tests, testeeConcurrent: during, pause_on_exit: true);
140 pause_on_exit: true);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698