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

Side by Side Diff: tests/standalone/src/io/HttpShutdownTest.dart

Issue 10173024: Change the error handling in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 5
6 #import("dart:isolate"); 6 #import("dart:isolate");
7 #import("dart:io"); 7 #import("dart:io");
8 8
9 void test1(int totalConnections) { 9 void test1(int totalConnections) {
10 // Server which just closes immediately. 10 // Server which just closes immediately.
(...skipping 28 matching lines...) Expand all
39 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 39 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
40 response.outputStream.writeString("!dlrow ,olleH"); 40 response.outputStream.writeString("!dlrow ,olleH");
41 response.outputStream.close(); 41 response.outputStream.close();
42 }; 42 };
43 43
44 int count = 0; 44 int count = 0;
45 HttpClient client = new HttpClient(); 45 HttpClient client = new HttpClient();
46 for (int i = 0; i < totalConnections; i++) { 46 for (int i = 0; i < totalConnections; i++) {
47 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); 47 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
48 conn.onRequest = (HttpClientRequest request) { 48 conn.onRequest = (HttpClientRequest request) {
49 request.contentLength = -1;
49 request.outputStream.writeString("Hello, world!"); 50 request.outputStream.writeString("Hello, world!");
50 request.outputStream.close(); 51 request.outputStream.close();
51 }; 52 };
52 conn.onResponse = (HttpClientResponse response) { 53 conn.onResponse = (HttpClientResponse response) {
53 count++; 54 count++;
54 if (count == totalConnections) { 55 if (count == totalConnections) {
55 client.shutdown(); 56 client.shutdown();
56 server.close(); 57 server.close();
57 } 58 }
58 }; 59 };
59 } 60 }
60 } 61 }
61 62
62 63
63 void test3(int totalConnections) { 64 void test3(int totalConnections) {
64 // Server which responds when request body has been received. 65 // Server which responds when request body has been received.
65 HttpServer server = new HttpServer(); 66 HttpServer server = new HttpServer();
66 server.listen("127.0.0.1", 0, totalConnections); 67 server.listen("127.0.0.1", 0, totalConnections);
67 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) { 68 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
69 request.inputStream.onData = () {
70 request.inputStream.read();
71 };
68 request.inputStream.onClosed = () { 72 request.inputStream.onClosed = () {
69 response.outputStream.writeString("!dlrow ,olleH"); 73 response.outputStream.writeString("!dlrow ,olleH");
70 response.outputStream.close(); 74 response.outputStream.close();
71 }; 75 };
72 }; 76 };
73 77
74 int count = 0; 78 int count = 0;
75 HttpClient client = new HttpClient(); 79 HttpClient client = new HttpClient();
76 for (int i = 0; i < totalConnections; i++) { 80 for (int i = 0; i < totalConnections; i++) {
77 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); 81 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
78 conn.onRequest = (HttpClientRequest request) { 82 conn.onRequest = (HttpClientRequest request) {
83 request.contentLength = -1;
79 request.outputStream.writeString("Hello, world!"); 84 request.outputStream.writeString("Hello, world!");
80 request.outputStream.close(); 85 request.outputStream.close();
81 }; 86 };
82 conn.onResponse = (HttpClientResponse response) { 87 conn.onResponse = (HttpClientResponse response) {
83 count++; 88 count++;
84 if (count == totalConnections) { 89 if (count == totalConnections) {
85 client.shutdown(); 90 client.shutdown();
86 server.close(); 91 server.close();
87 } 92 }
88 }; 93 };
89 } 94 }
90 } 95 }
91 96
92 97
93 void main() { 98 void main() {
94 test1(1); 99 test1(1);
95 test1(10); 100 test1(10);
96 test2(1); 101 test2(1);
97 test2(10); 102 test2(10);
98 test3(1); 103 test3(1);
99 test3(10); 104 test3(10);
100 } 105 }
OLDNEW
« no previous file with comments | « tests/standalone/src/io/HttpServerSocketTest.dart ('k') | tests/standalone/src/io/ProcessBrokenPipeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698