OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked | |
5 | |
6 import 'dart:async'; | |
7 import 'dart:isolate' as I; | |
8 | |
9 import 'package:observatory/service_io.dart'; | |
10 import 'package:unittest/unittest.dart'; | |
11 | |
12 import 'test_helper.dart'; | |
13 | |
14 final spawnCount = 4; | |
15 final resumeCount = spawnCount ~/ 2; | |
16 final isolates = []; | |
17 | |
18 void spawnEntry(int i) { | |
19 } | |
20 | |
21 Future before() async { | |
22 // Spawn spawnCount long lived isolates. | |
23 for (var i = 0; i < spawnCount; i++) { | |
24 var isolate = await I.Isolate.spawn(spawnEntry, i); | |
25 isolates.add(isolate); | |
26 } | |
27 print('spawned all isolates'); | |
28 } | |
29 | |
30 Future during() async { | |
31 } | |
32 | |
33 var tests = [ | |
34 (VM vm) async { | |
35 expect(vm.isolates.length, spawnCount + 1); | |
36 }, | |
37 (VM vm) async { | |
38 // Load each isolate. | |
39 for (var isolate in vm.isolates) { | |
40 await isolate.load(); | |
41 } | |
42 }, | |
43 (VM vm) async { | |
44 var pausedCount = 0; | |
45 var runningCount = 0; | |
46 for (var isolate in vm.isolates) { | |
47 if (isolate.paused) { | |
48 pausedCount++; | |
49 } else { | |
50 runningCount++; | |
51 } | |
52 } | |
53 expect(pausedCount, spawnCount); | |
54 expect(runningCount, 1); | |
55 }, | |
56 (VM vm) async { | |
57 var resumedReceived = 0; | |
58 var eventsDone = processServiceEvents(vm, (event, sub, completer) { | |
59 if (event.eventType == ServiceEvent.kIsolateExit) { | |
60 resumedReceived++; | |
61 if (resumedReceived == resumeCount) { | |
62 sub.cancel(); | |
63 completer.complete(null); | |
64 } | |
65 } | |
66 }); | |
67 var resumesIssued = 0; | |
68 var isolateList = vm.isolates.toList(); | |
69 for (var isolate in isolateList) { | |
70 if (isolate.name.endsWith('main')) { | |
71 continue; | |
72 } | |
73 try { | |
74 resumesIssued++; | |
75 await isolate.resume(); | |
76 } catch(_) {} | |
77 if (resumesIssued == resumeCount) { | |
78 break; | |
79 } | |
80 } | |
81 return eventsDone; | |
82 }, | |
83 (VM vm) async { | |
84 var pausedCount = 0; | |
85 var runningCount = 0; | |
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 }, | |
96 ]; | |
97 | |
98 main(args) async => runVMTests(args, tests, | |
99 testeeBefore: before, | |
100 testeeConcurrent: during, | |
101 pause_on_exit: true); | |
OLD | NEW |