OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // This test creates a lot of isolates. This is meant to exhaust | 5 // This test creates a lot of isolates. This is meant to exhaust |
6 // resources if the isolates aren't closed correctly (which happened | 6 // resources if the isolates aren't closed correctly (which happened |
7 // in dart2js). | 7 // in dart2js). |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
11 | 11 |
12 // TODO(12588): Remove this import when we have wrapper-less testing. | 12 // TODO(12588): Remove this import when we have wrapper-less testing. |
13 import 'dart:html'; | 13 import 'dart:html'; |
14 | 14 |
15 worker() { | 15 worker(SendPort replyTo) { |
16 port.receive((String uri, SendPort replyTo) { | 16 replyTo.send('Hello from Worker'); |
17 replyTo.send('Hello from Worker'); | |
18 port.close(); | |
19 }); | |
20 } | 17 } |
21 | 18 |
22 main() { | 19 main() { |
23 try { | 20 try { |
24 // Create a Worker to confuse broken isolate implementation in dart2js. | 21 // Create a Worker to confuse broken isolate implementation in dart2js. |
25 new Worker('data:application/javascript,').terminate(); | 22 new Worker('data:application/javascript,').terminate(); |
26 } catch (e) { | 23 } catch (e) { |
27 // Ignored. | 24 // Ignored. |
28 } | 25 } |
29 var doneClosure; | 26 var doneClosure; |
30 int isolateCount = 0; | 27 int isolateCount = 0; |
31 spawnMany(reply) { | 28 spawnMany(reply) { |
32 if (reply != 'Hello from Worker') { | 29 if (reply != 'Hello from Worker') { |
33 throw new Exception('Unexpected reply from worker: $reply'); | 30 throw new Exception('Unexpected reply from worker: $reply'); |
34 } | 31 } |
35 if (++isolateCount > 200) { | 32 if (++isolateCount > 200) { |
36 port.close(); | |
37 window.postMessage('unittest-suite-success', '*'); | 33 window.postMessage('unittest-suite-success', '*'); |
38 return; | 34 return; |
39 } | 35 } |
40 spawnFunction(worker).call('').then(spawnMany); | 36 ReceivePort response = new ReceivePort(); |
| 37 var remote = Isolate.spawn(worker, response.sendPort); |
| 38 remote.then((_) => response.first).then(spawnMany); |
41 print('isolateCount = $isolateCount'); | 39 print('isolateCount = $isolateCount'); |
42 } | 40 } |
43 | 41 |
44 spawnMany('Hello from Worker'); | 42 spawnMany('Hello from Worker'); |
45 window.postMessage('unittest-suite-wait-for-done', '*'); | 43 window.postMessage('unittest-suite-wait-for-done', '*'); |
46 } | 44 } |
OLD | NEW |