OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // This test creates a lot of isolates. This is meant to exhaust |
| 6 // resources if the isolates aren't closed correctly (which happened |
| 7 // in dart2js). |
| 8 |
| 9 import 'dart:async'; |
| 10 import 'dart:html'; |
| 11 import 'dart:isolate'; |
| 12 |
| 13 // TODO(ahe): Remove dependency on unittest when tests are wrapperless. |
| 14 import 'package:unittest/unittest.dart'; |
| 15 import 'package:unittest/html_config.dart'; |
| 16 |
| 17 const bool IS_UNITTEST = true; |
| 18 |
| 19 worker() { |
| 20 port.receive((String uri, SendPort replyTo) { |
| 21 replyTo.send('Hello from Worker'); |
| 22 port.close(); |
| 23 }); |
| 24 } |
| 25 |
| 26 main() { |
| 27 useHtmlConfiguration(); |
| 28 try { |
| 29 // Create a Worker to confuse broken isolate implementation in dart2js. |
| 30 new Worker('data:application/javascript,').terminate(); |
| 31 } catch (e) { |
| 32 // Ignored. |
| 33 } |
| 34 var doneClosure; |
| 35 int isolateCount = 0; |
| 36 spawnMany(reply) { |
| 37 if (reply != 'Hello from Worker') { |
| 38 throw new Exception('Unexpected reply from worker: $reply'); |
| 39 } |
| 40 if (++isolateCount > 200) { |
| 41 if (IS_UNITTEST) { |
| 42 doneClosure(); |
| 43 } else { |
| 44 port.close(); |
| 45 window.postMessage('unittest-suite-done', '*'); |
| 46 } |
| 47 return; |
| 48 } |
| 49 spawnFunction(worker).call('').then(spawnMany); |
| 50 print('isolateCount = $isolateCount'); |
| 51 } |
| 52 |
| 53 if (IS_UNITTEST) { |
| 54 test('stress test', () { |
| 55 spawnMany('Hello from Worker'); |
| 56 doneClosure = expectAsync0(() {}); |
| 57 }); |
| 58 } else { |
| 59 spawnMany('Hello from Worker'); |
| 60 window.postMessage('unittest-suite-wait-for-done', '*'); |
| 61 } |
| 62 } |
OLD | NEW |