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

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

Issue 9958060: Make sure to don't close the HTTP Server until all the headers have been flushed. (Closed) Base URL: http://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
« 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
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 #import("dart:io"); 5 #import("dart:io");
6 #import("dart:isolate"); 6 #import("dart:isolate");
7 7
8 void testListenOn() { 8 void testListenOn() {
9 ServerSocket socket = new ServerSocket("127.0.0.1", 0, 5); 9 ServerSocket socket = new ServerSocket("127.0.0.1", 0, 5);
10 10
11 socket.onError = (Exception e) { 11 socket.onError = (Exception e) {
12 Expect.fail("ServerSocket closed unexpected"); 12 Expect.fail("ServerSocket closed unexpected");
13 }; 13 };
14 14
15 void test(void onDone()) { 15 void test(void onDone()) {
16 HttpServer server = new HttpServer(); 16 HttpServer server = new HttpServer();
17 Expect.throws(() => server.port); 17 Expect.throws(() => server.port);
18 18
19 ReceivePort serverPort = new ReceivePort(); 19 ReceivePort serverPort = new ReceivePort();
20 server.onRequest = (HttpRequest request, HttpResponse response) { 20 server.onRequest = (HttpRequest request, HttpResponse response) {
21 request.inputStream.onClosed = () { 21 request.inputStream.onClosed = () {
22 response.outputStream.close(); 22 response.outputStream.close();
23 server.close();
24 Expect.throws(() => server.port);
25 serverPort.close(); 23 serverPort.close();
26 onDone();
27 }; 24 };
28 }; 25 };
29 26
30 server.onError = (Exception e) { 27 server.onError = (Exception e) {
31 Expect.fail("Unexpected error in Http Server: $e"); 28 Expect.fail("Unexpected error in Http Server: $e");
32 }; 29 };
33 30
34 server.listenOn(socket); 31 server.listenOn(socket);
35 Expect.equals(socket.port, server.port); 32 Expect.equals(socket.port, server.port);
36 33
37 HttpClient client = new HttpClient(); 34 HttpClient client = new HttpClient();
38 HttpClientConnection conn = client.get("127.0.0.1", socket.port, "/"); 35 HttpClientConnection conn = client.get("127.0.0.1", socket.port, "/");
39 conn.onRequest = (HttpClientRequest request) { 36 conn.onRequest = (HttpClientRequest request) {
40 request.outputStream.close(); 37 request.outputStream.close();
41 }; 38 };
42 ReceivePort clientPort = new ReceivePort(); 39 ReceivePort clientPort = new ReceivePort();
43 conn.onResponse = (HttpClientResponse response) { 40 conn.onResponse = (HttpClientResponse response) {
44 response.inputStream.onClosed = () { 41 response.inputStream.onClosed = () {
45 client.shutdown(); 42 client.shutdown();
46 clientPort.close(); 43 clientPort.close();
44 server.close();
45 Expect.throws(() => server.port);
46 onDone();
47 }; 47 };
48 }; 48 };
49 conn.onError = (Exception e) { 49 conn.onError = (Exception e) {
50 Expect.fail("Unexpected error in Http Client"); 50 Expect.fail("Unexpected error in Http Client: $e");
51 }; 51 };
52 }; 52 };
53 53
54 // Test two connection after each other. 54 // Test two connection after each other.
55 test(() { 55 test(() {
56 test(() { 56 test(() {
57 socket.close(); 57 socket.close();
58 }); 58 });
59 }); 59 });
60 } 60 }
61 61
62 void main() { 62 void main() {
63 testListenOn(); 63 testListenOn();
64 } 64 }
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