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:html'; | |
11 import 'dart:isolate'; | 10 import 'dart:isolate'; |
12 | 11 |
13 // TODO(ahe): Remove dependency on unittest when tests are wrapperless. | 12 // TODO(ahe): Remove this import when we have wrapper-less testing. |
14 import 'package:unittest/unittest.dart'; | 13 import 'dart:html'; |
15 import 'package:unittest/html_config.dart'; | |
16 | |
17 const bool IS_UNITTEST = true; | |
18 | 14 |
19 worker() { | 15 worker() { |
20 port.receive((String uri, SendPort replyTo) { | 16 port.receive((String uri, SendPort replyTo) { |
21 replyTo.send('Hello from Worker'); | 17 replyTo.send('Hello from Worker'); |
22 port.close(); | 18 port.close(); |
23 }); | 19 }); |
24 } | 20 } |
25 | 21 |
26 main() { | 22 main() { |
27 useHtmlConfiguration(); | |
28 try { | 23 try { |
29 // Create a Worker to confuse broken isolate implementation in dart2js. | 24 // Create a Worker to confuse broken isolate implementation in dart2js. |
30 new Worker('data:application/javascript,').terminate(); | 25 new Worker('data:application/javascript,').terminate(); |
31 } catch (e) { | 26 } catch (e) { |
32 // Ignored. | 27 // Ignored. |
33 } | 28 } |
34 var doneClosure; | 29 var doneClosure; |
35 int isolateCount = 0; | 30 int isolateCount = 0; |
36 spawnMany(reply) { | 31 spawnMany(reply) { |
37 if (reply != 'Hello from Worker') { | 32 if (reply != 'Hello from Worker') { |
38 throw new Exception('Unexpected reply from worker: $reply'); | 33 throw new Exception('Unexpected reply from worker: $reply'); |
39 } | 34 } |
40 if (++isolateCount > 200) { | 35 if (++isolateCount > 200) { |
41 if (IS_UNITTEST) { | 36 port.close(); |
42 doneClosure(); | 37 window.postMessage('unittest-suite-success', '*'); |
43 } else { | |
44 port.close(); | |
45 window.postMessage('unittest-suite-done', '*'); | |
46 } | |
47 return; | 38 return; |
48 } | 39 } |
49 spawnFunction(worker).call('').then(spawnMany); | 40 spawnFunction(worker).call('').then(spawnMany); |
50 print('isolateCount = $isolateCount'); | 41 print('isolateCount = $isolateCount'); |
51 } | 42 } |
52 | 43 |
53 if (IS_UNITTEST) { | 44 spawnMany('Hello from Worker'); |
54 test('stress test', () { | 45 window.postMessage('unittest-suite-wait-for-done', '*'); |
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 } | 46 } |
OLD | NEW |