| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 4 |
| 5 library MandelIsolateTest; | 5 library MandelIsolateTest; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'dart:math'; | 8 import 'dart:math'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import "remote_unittest_helper.dart"; | 10 import "remote_unittest_helper.dart"; |
| 11 | 11 |
| 12 const TERMINATION_MESSAGE = -1; | 12 const TERMINATION_MESSAGE = -1; |
| 13 const N = 100; | 13 const N = 100; |
| 14 const ISOLATES = 20; | 14 const ISOLATES = 20; |
| 15 | 15 |
| 16 void main([args, port]) { | 16 void main([args, port]) { |
| 17 if (testRemote(main, port)) return; | 17 if (testRemote(main, port)) return; |
| 18 // Test is really slow in debug builds of the VM. | 18 // Test is really slow in debug builds of the VM. |
| 19 var configuration = unittestConfiguration; | 19 var configuration = unittestConfiguration; |
| 20 configuration.timeout = const Duration(seconds: 480); | 20 configuration.timeout = const Duration(seconds: 480); |
| 21 test("Render Mandelbrot in parallel", () { | 21 test("Render Mandelbrot in parallel", () { |
| 22 final state = new MandelbrotState(); | 22 final state = new MandelbrotState(); |
| 23 state._validated.future.then(expectAsync1((result) { | 23 state._validated.future.then(expectAsync((result) { |
| 24 expect(result, isTrue); | 24 expect(result, isTrue); |
| 25 })); | 25 })); |
| 26 for (int i = 0; i < min(ISOLATES, N); i++) state.startClient(i); | 26 for (int i = 0; i < min(ISOLATES, N); i++) state.startClient(i); |
| 27 }); | 27 }); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 class MandelbrotState { | 31 class MandelbrotState { |
| 32 | 32 |
| 33 MandelbrotState() { | 33 MandelbrotState() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (message != TERMINATION_MESSAGE) { | 152 if (message != TERMINATION_MESSAGE) { |
| 153 int line = message[0]; | 153 int line = message[0]; |
| 154 SendPort replyTo = message[1]; | 154 SendPort replyTo = message[1]; |
| 155 replyTo.send(processLine(line)); | 155 replyTo.send(processLine(line)); |
| 156 } else { | 156 } else { |
| 157 port.close(); | 157 port.close(); |
| 158 } | 158 } |
| 159 }); | 159 }); |
| 160 replyPort.send(port.sendPort); | 160 replyPort.send(port.sendPort); |
| 161 } | 161 } |
| OLD | NEW |