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

Unified Diff: runtime/tests/vm/dart/spawn_shutdown_test.dart

Issue 1447353002: Start isolates in a separate thread. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: reupload Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/isolate_patch.dart ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « runtime/lib/isolate_patch.dart ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698