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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "package:expect/expect.dart";
11 import 'dart:async';
12 import 'dart:io';
13 import 'dart:isolate';
14
15 Future<int> runServer(int port, int connections, bool clean) {
16 var completer = new Completer();
17 HttpServer.bind("127.0.0.1", port).then((server) {
18 int i = 0;
19 server.listen((request) {
20 request.pipe(request.response);
21 i++;
22 if (!clean && i == 10) {
23 int port = server.port;
24 server.close().then((_) => completer.complete(port));
25 }
26 });
27
28 Future.wait(new List.generate(connections, (_) {
29 var client = new HttpClient();
30 return client.get("127.0.0.1", server.port, "/")
31 .then((request) => request.close())
32 .then((response) => response.drain())
33 .catchError((e) { if (clean) throw e; });
34 })).then((_) {
35 if (clean) {
36 int port = server.port;
37 server.close().then((_) => completer.complete(port));
38 }
39 });
40 });
41 return completer.future;
42 }
43
44
45 void testReusePort() {
46 var keepAlive = new ReceivePort();
47 runServer(0, 10, true).then((int port) {
48 // Stress test the port reusing it 10 times.
49 Future.forEach(new List(10), (_) {
50 return runServer(port, 10, true);
51 }).then((_) {
52 keepAlive.close();
53 });
54 });
55 }
56
57
58 void testUncleanReusePort() {
59 var keepAlive = new ReceivePort();
60 runServer(0, 10, false).then((int port) {
61 // Stress test the port reusing it 10 times.
62 Future.forEach(new List(10), (_) {
63 return runServer(port, 10, false);
64 }).then((_) {
65 keepAlive.close();
66 });
67 });
68 }
69
70
71 void main() {
72 testReusePort();
73 testUncleanReusePort();
74 }
OLDNEW
« 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