| 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 // VMOptions= | 5 // VMOptions= |
| 6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
| 7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
| 8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
| 9 | 9 |
| 10 import "package:expect/expect.dart"; | |
| 11 import 'dart:async'; | 10 import 'dart:async'; |
| 12 import 'dart:io'; | 11 import 'dart:io'; |
| 13 import 'dart:isolate'; | 12 |
| 13 import "package:async_helper/async_helper.dart"; |
| 14 import "package:expect/expect.dart"; |
| 14 | 15 |
| 15 Future<int> runServer(int port, int connections, bool clean) { | 16 Future<int> runServer(int port, int connections, bool clean) { |
| 16 var completer = new Completer(); | 17 var completer = new Completer(); |
| 17 HttpServer.bind("127.0.0.1", port).then((server) { | 18 HttpServer.bind("127.0.0.1", port).then((server) { |
| 18 int i = 0; | 19 int i = 0; |
| 19 server.listen((request) { | 20 server.listen((request) { |
| 20 request.pipe(request.response); | 21 request.pipe(request.response); |
| 21 i++; | 22 i++; |
| 22 if (!clean && i == 10) { | 23 if (!clean && i == 10) { |
| 23 int port = server.port; | 24 int port = server.port; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 36 int port = server.port; | 37 int port = server.port; |
| 37 server.close().then((_) => completer.complete(port)); | 38 server.close().then((_) => completer.complete(port)); |
| 38 } | 39 } |
| 39 }); | 40 }); |
| 40 }); | 41 }); |
| 41 return completer.future; | 42 return completer.future; |
| 42 } | 43 } |
| 43 | 44 |
| 44 | 45 |
| 45 void testReusePort() { | 46 void testReusePort() { |
| 46 var keepAlive = new ReceivePort(); | 47 asyncStart(); |
| 47 runServer(0, 10, true).then((int port) { | 48 runServer(0, 10, true).then((int port) { |
| 48 // Stress test the port reusing it 10 times. | 49 // Stress test the port reusing it 10 times. |
| 49 Future.forEach(new List(10), (_) { | 50 Future.forEach(new List(10), (_) { |
| 50 return runServer(port, 10, true); | 51 return runServer(port, 10, true); |
| 51 }).then((_) { | 52 }).then((_) { |
| 52 keepAlive.close(); | 53 asyncEnd(); |
| 53 }); | 54 }); |
| 54 }); | 55 }); |
| 55 } | 56 } |
| 56 | 57 |
| 57 | 58 |
| 58 void testUncleanReusePort() { | 59 void testUncleanReusePort() { |
| 59 var keepAlive = new ReceivePort(); | 60 asyncStart(); |
| 60 runServer(0, 10, false).then((int port) { | 61 runServer(0, 10, false).then((int port) { |
| 61 // Stress test the port reusing it 10 times. | 62 // Stress test the port reusing it 10 times. |
| 62 Future.forEach(new List(10), (_) { | 63 Future.forEach(new List(10), (_) { |
| 63 return runServer(port, 10, false); | 64 return runServer(port, 10, false); |
| 64 }).then((_) { | 65 }).then((_) { |
| 65 keepAlive.close(); | 66 asyncEnd(); |
| 66 }); | 67 }); |
| 67 }); | 68 }); |
| 68 } | 69 } |
| 69 | 70 |
| 70 | 71 |
| 71 void main() { | 72 void main() { |
| 72 testReusePort(); | 73 testReusePort(); |
| 73 testUncleanReusePort(); | 74 testUncleanReusePort(); |
| 74 } | 75 } |
| OLD | NEW |