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

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

Issue 1293383011: Add an IsolateRunnable event to the service protocol. Improve service docs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:isolate' as I; 8 import 'dart:isolate' as I;
8 9
9 import 'package:observatory/service_io.dart'; 10 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
11 12
12 import 'test_helper.dart'; 13 import 'test_helper.dart';
13 14
14 final spawnCount = 4; 15 final spawnCount = 4;
15 final resumeCount = spawnCount ~/ 2; 16 final resumeCount = spawnCount ~/ 2;
16 final isolates = []; 17 final isolates = [];
17 18
18 void spawnEntry(int i) { 19 void spawnEntry(int i) {
19 } 20 }
20 21
21 Future before() async { 22 Future during() async {
23 debugger();
22 // Spawn spawnCount long lived isolates. 24 // Spawn spawnCount long lived isolates.
23 for (var i = 0; i < spawnCount; i++) { 25 for (var i = 0; i < spawnCount; i++) {
24 var isolate = await I.Isolate.spawn(spawnEntry, i); 26 var isolate = await I.Isolate.spawn(spawnEntry, i);
25 isolates.add(isolate); 27 isolates.add(isolate);
26 } 28 }
27 print('spawned all isolates'); 29 print('spawned all isolates');
28 } 30 }
29 31
30 Future during() async {
31 }
32
33 int numPaused(vm) { 32 int numPaused(vm) {
34 int paused = 0; 33 int paused = 0;
35 for (var isolate in vm.isolates) { 34 for (var isolate in vm.isolates) {
36 if (isolate.paused) { 35 if (isolate.paused) {
37 paused++; 36 paused++;
38 } 37 }
39 } 38 }
40 return paused; 39 return paused;
41 } 40 }
42 41
43 var tests = [ 42 var tests = [
44 (VM vm) async { 43 (VM vm) async {
44 expect(vm.isolates.length, 1);
45 await hasStoppedAtBreakpoint(vm.isolates[0]);
46 },
47
48 (VM vm) async {
45 Completer completer = new Completer(); 49 Completer completer = new Completer();
46 var stream = await vm.getEventStream(VM.kIsolateStream); 50 var stream = await vm.getEventStream(VM.kIsolateStream);
47 if (vm.isolates.length < spawnCount + 1) { 51 var subscription;
48 var subscription; 52 int startCount = 0;
49 subscription = stream.listen((ServiceEvent event) { 53 int runnableCount = 0;
50 if (event.kind == ServiceEvent.kIsolateStart) { 54 subscription = stream.listen((ServiceEvent event) {
51 if (vm.isolates.length == (spawnCount + 1)) { 55 if (event.kind == ServiceEvent.kIsolateStart) {
52 subscription.cancel(); 56 startCount++;
53 completer.complete(null); 57 }
54 } 58 if (event.kind == ServiceEvent.kIsolateRunnable) {
55 } 59 runnableCount++;
56 }); 60 }
57 await completer.future; 61 if (runnableCount == spawnCount) {
58 } 62 subscription.cancel();
63 completer.complete(null);
64 }
65 });
66 expect(vm.isolates.length, 1);
67 vm.isolates[0].resume();
68 await completer.future;
69 expect(startCount, spawnCount);
70 expect(runnableCount, spawnCount);
59 expect(vm.isolates.length, spawnCount + 1); 71 expect(vm.isolates.length, spawnCount + 1);
60 }, 72 },
61 73
62 (VM vm) async { 74 (VM vm) async {
63 // Load each isolate. 75 // Load each isolate.
64 for (var isolate in vm.isolates) { 76 for (var isolate in vm.isolates) {
65 await isolate.load(); 77 await isolate.load();
66 } 78 }
67 }, 79 },
68 80
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 129 }
118 await completer.future; 130 await completer.future;
119 }, 131 },
120 132
121 (VM vm) async { 133 (VM vm) async {
122 expect(numPaused(vm), spawnCount + 1 - resumeCount); 134 expect(numPaused(vm), spawnCount + 1 - resumeCount);
123 }, 135 },
124 ]; 136 ];
125 137
126 main(args) async => runVMTests(args, tests, 138 main(args) async => runVMTests(args, tests,
127 testeeBefore: before,
128 testeeConcurrent: during, 139 testeeConcurrent: during,
129 pause_on_exit: true); 140 pause_on_exit: true);
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698