Index: runtime/tests/vm/dart/spawn_shutdown_test.dart |
diff --git a/runtime/tests/vm/dart/spawn_shutdown_test.dart b/runtime/tests/vm/dart/spawn_shutdown_test.dart |
index 794e7375220efc814db156f99fd7fc42d3873f93..238c3259eb6650d92d5b30234c492a3184f8b6ce 100644 |
--- a/runtime/tests/vm/dart/spawn_shutdown_test.dart |
+++ b/runtime/tests/vm/dart/spawn_shutdown_test.dart |
@@ -3,30 +3,47 @@ |
// BSD-style license that can be found in the LICENSE file. |
import 'dart:async'; |
+import 'dart:io'; |
import 'dart:isolate'; |
-// Spawn an isolate |foo| that will continue trying to spawn isolates even after |
-// the timer in |main| completes. This test ensures that the VM can shutdown |
-// correctly even while an isolate is attempting to spawn more isolates. |
+// This test attempts to check that the vm can shutdown cleanly when |
+// isolates are starting and stopping. |
+// |
+// We spawn a set of workers. Each worker will kill its parent |
+// worker (if any) and then spawn a child worker. We start these |
+// workers in a staggered fashion in an attempt to see a variety of |
+// isolate states at the time that this program terminates. |
-isolate1(sendPort) { |
- var receivePort = new ReceivePort(); |
- sendPort.send(receivePort.sendPort); |
- receivePort.listen((msg) {}); |
-} |
+void worker(SendPort parentPort) { |
+ var port = new RawReceivePort(); |
+ |
+ // This worker will exit when it receives any message. |
+ port.handler = (_) { port.close(); }; |
-void foo(_) { |
- while (true) { |
- var receivePort = new ReceivePort(); |
- Isolate.spawn(isolate1, receivePort.sendPort); |
- receivePort.listen((sendPort) { |
- Isolate.spawn(isolate1,sendPort); |
- receivePort.close(); |
- }); |
+ // Send a message to terminate our parent isolate. |
+ if (parentPort != null) { |
+ parentPort.send(null); |
} |
+ |
+ // Spawn a child worker. |
+ Isolate.spawn(worker, port.sendPort); |
} |
void main() { |
- Isolate.spawn(foo, null); |
- new Timer(const Duration(seconds: 10), () {}); |
+ const numWorkers = 50; |
+ const delay = const Duration(milliseconds:(1000 ~/ numWorkers)); |
+ const exitDelay = const Duration(seconds: 2); |
+ |
+ // Take about a second to spin up our workers in a staggered |
+ // fashion. We want to maximize the chance that they will be in a |
+ // variety of states when the vm shuts down. |
+ print('Starting ${numWorkers} workers...'); |
+ for (int i = 0; i < numWorkers; i++) { |
+ Isolate.spawn(worker, null); |
+ sleep(delay); |
+ } |
+ |
+ // Let them spin for a bit before terminating the program. |
+ print('Waiting for ${exitDelay} before exit...'); |
+ sleep(exitDelay); |
} |