Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: tests/standalone/io/http_reuse_server_port_test.dart

Issue 19653004: Add test for reusing the port of a server socket, after the server's close future is completed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add unclean close version. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_reuse_server_port_test.dart
diff --git a/tests/standalone/io/http_reuse_server_port_test.dart b/tests/standalone/io/http_reuse_server_port_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4da68026bb6500bf780d2b0952b5244ad70138ac
--- /dev/null
+++ b/tests/standalone/io/http_reuse_server_port_test.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// VMOptions=
+// VMOptions=--short_socket_read
+// VMOptions=--short_socket_write
+// VMOptions=--short_socket_read --short_socket_write
+
+import "package:expect/expect.dart";
+import 'dart:async';
+import 'dart:io';
+import 'dart:isolate';
+
+Future<int> runServer(int port, int connections, bool clean) {
+ var completer = new Completer();
+ HttpServer.bind("127.0.0.1", port).then((server) {
+ int i = 0;
+ server.listen((request) {
+ request.pipe(request.response);
+ i++;
+ if (!clean && i == 10) {
+ int port = server.port;
+ server.close().then((_) => completer.complete(port));
+ }
+ });
+
+ Future.wait(new List.generate(connections, (_) {
+ var client = new HttpClient();
+ return client.get("127.0.0.1", server.port, "/")
+ .then((request) => request.close())
+ .then((response) => response.drain())
+ .catchError((e) { if (clean) throw e; });
+ })).then((_) {
+ if (clean) {
+ int port = server.port;
+ server.close().then((_) => completer.complete(port));
+ }
+ });
+ });
+ return completer.future;
+}
+
+
+void testReusePort() {
+ var keepAlive = new ReceivePort();
+ runServer(0, 10, true).then((int port) {
+ // Stress test the port reusing it 10 times.
+ Future.forEach(new List(10), (_) {
+ return runServer(port, 10, true);
+ }).then((_) {
+ keepAlive.close();
+ });
+ });
+}
+
+
+void testUncleanReusePort() {
+ var keepAlive = new ReceivePort();
+ runServer(0, 10, false).then((int port) {
+ // Stress test the port reusing it 10 times.
+ Future.forEach(new List(10), (_) {
+ return runServer(port, 10, false);
+ }).then((_) {
+ keepAlive.close();
+ });
+ });
+}
+
+
+void main() {
+ testReusePort();
+ testUncleanReusePort();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698