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

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

Issue 1093043004: Do not JSON encode the 'result' of a service rpc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 5 years, 8 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 | Annotate | Revision Log
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=--compile-all --error_on_bad_type --error_on_bad_override 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:isolate' as I; 7 import 'dart:isolate' as I;
8 8
9 import 'package:observatory/service_io.dart'; 9 import 'package:observatory/service_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 12 matching lines...) Expand all
23 for (var i = 0; i < spawnCount; i++) { 23 for (var i = 0; i < spawnCount; i++) {
24 var isolate = await I.Isolate.spawn(spawnEntry, i); 24 var isolate = await I.Isolate.spawn(spawnEntry, i);
25 isolates.add(isolate); 25 isolates.add(isolate);
26 } 26 }
27 print('spawned all isolates'); 27 print('spawned all isolates');
28 } 28 }
29 29
30 Future during() async { 30 Future during() async {
31 } 31 }
32 32
33 int numPaused(vm) {
34 int paused = 0;
35 for (var isolate in vm.isolates) {
36 if (isolate.paused) {
37 paused++;
38 }
39 }
40 return paused;
41 }
42
43 int numRunning(vm) {
44 int running = 0;
45 for (var isolate in vm.isolates) {
46 if (!isolate.paused) {
47 running++;
48 }
49 }
50 return running;
51 }
52
33 var tests = [ 53 var tests = [
34 (VM vm) async { 54 (VM vm) async {
55 // Wait for the testee to start all of the isolates.
56 if (vm.isolates.length != spawnCount + 1) {
57 await processServiceEvents(vm, (event, sub, completer) {
58 if (event.eventType == ServiceEvent.kIsolateStart) {
59 if (vm.isolates.length == spawnCount + 1) {
60 sub.cancel();
61 completer.complete(null);
62 }
63 }
64 });
65 }
35 expect(vm.isolates.length, spawnCount + 1); 66 expect(vm.isolates.length, spawnCount + 1);
36 }, 67 },
68
37 (VM vm) async { 69 (VM vm) async {
38 // Load each isolate. 70 // Load each isolate.
39 for (var isolate in vm.isolates) { 71 for (var isolate in vm.isolates) {
40 await isolate.load(); 72 await isolate.load();
41 } 73 }
42 }, 74 },
75
43 (VM vm) async { 76 (VM vm) async {
44 var pausedCount = 0; 77 // Wait for all spawned isolates to hit pause-at-exit.
45 var runningCount = 0; 78 if (numPaused(vm) != spawnCount) {
46 for (var isolate in vm.isolates) { 79 await processServiceEvents(vm, (event, sub, completer) {
47 if (isolate.paused) { 80 if (event.eventType == ServiceEvent.kPauseExit) {
48 pausedCount++; 81 if (numPaused(vm) == spawnCount) {
49 } else { 82 sub.cancel();
50 runningCount++; 83 completer.complete(null);
51 } 84 }
85 }
86 });
52 } 87 }
53 expect(pausedCount, spawnCount); 88 expect(numPaused(vm), spawnCount);
54 expect(runningCount, 1); 89 expect(numRunning(vm), 1);
55 }, 90 },
91
92
56 (VM vm) async { 93 (VM vm) async {
57 var resumedReceived = 0; 94 var resumedReceived = 0;
58 var eventsDone = processServiceEvents(vm, (event, sub, completer) { 95 var eventsDone = processServiceEvents(vm, (event, sub, completer) {
59 if (event.eventType == ServiceEvent.kIsolateExit) { 96 if (event.eventType == ServiceEvent.kIsolateExit) {
60 resumedReceived++; 97 resumedReceived++;
61 if (resumedReceived == resumeCount) { 98 if (resumedReceived == resumeCount) {
62 sub.cancel(); 99 sub.cancel();
63 completer.complete(null); 100 completer.complete(null);
64 } 101 }
65 } 102 }
66 }); 103 });
67 var resumesIssued = 0; 104 var resumesIssued = 0;
68 var isolateList = vm.isolates.toList(); 105 var isolateList = vm.isolates.toList();
69 for (var isolate in isolateList) { 106 for (var isolate in isolateList) {
70 if (isolate.name.endsWith('main')) { 107 if (isolate.name.endsWith('main')) {
71 continue; 108 continue;
72 } 109 }
73 try { 110 try {
74 resumesIssued++; 111 resumesIssued++;
75 await isolate.resume(); 112 await isolate.resume();
76 } catch(_) {} 113 } catch(_) {}
77 if (resumesIssued == resumeCount) { 114 if (resumesIssued == resumeCount) {
78 break; 115 break;
79 } 116 }
80 } 117 }
81 return eventsDone; 118 return eventsDone;
82 }, 119 },
120
83 (VM vm) async { 121 (VM vm) async {
84 var pausedCount = 0; 122 expect(numPaused(vm), spawnCount - resumeCount);
85 var runningCount = 0; 123 expect(numRunning(vm), 1);
86 for (var isolate in vm.isolates) {
87 if (isolate.paused) {
88 pausedCount++;
89 } else {
90 runningCount++;
91 }
92 }
93 expect(pausedCount, spawnCount - resumeCount);
94 expect(runningCount, 1);
95 }, 124 },
96 ]; 125 ];
97 126
98 main(args) async => runVMTests(args, tests, 127 main(args) async => runVMTests(args, tests,
99 testeeBefore: before, 128 testeeBefore: before,
100 testeeConcurrent: during, 129 testeeConcurrent: during,
101 pause_on_exit: true); 130 pause_on_exit: true);
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/gc_test.dart ('k') | runtime/observatory/tests/service/malformed_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698