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

Side by Side Diff: tests/standalone/io/http_server_early_server_close_test.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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 import "dart:async"; 5 import "dart:async";
6 import "dart:io"; 6 import "dart:io";
7 import "dart:isolate"; 7 import "dart:isolate";
8 8
9 class Server { 9 class Server {
10 Server() { 10 static Future<int> start() {
11 HttpServer server = new HttpServer(); 11 return HttpServer.bind("127.0.0.1", 0).then((server) {
12 server.listen("127.0.0.1", 0); 12 server.listen((HttpRequest request) {
13 port = server.port; 13 Timer.run(server.close);
14 server.defaultRequestHandler = 14 }, onError: (e) {
15 (HttpRequest request, HttpResponse response) { 15 Expect.fail("No server errors expected: $e");
16 Timer.run(server.close); 16 });
17 }; 17 return server.port;
18 server.onError = (e) { 18 });
19 Expect.fail("No server errors expected: $e");
20 };
21 } 19 }
22 int port;
23 } 20 }
24 21
25 class Client { 22 class Client {
26 Client(int port) { 23 Client(int port) {
27 ReceivePort r = new ReceivePort(); 24 ReceivePort r = new ReceivePort();
28 HttpClient client = new HttpClient(); 25 HttpClient client = new HttpClient();
29 HttpClientConnection c = client.get("127.0.0.1", port, "/"); 26 client.get("127.0.0.1", port, "/")
30 c.onRequest = (HttpClientRequest request) { 27 .then((HttpClientRequest request) {
31 request.outputStream.close(); 28 return request.close();
32 }; 29 })
33 c.onResponse = (HttpClientResponse response) { 30 .then((HttpClientResponse response) {
34 Expect.fail("Response should not be given, as not data was returned."); 31 Expect.fail(
35 }; 32 "Response should not be given, as not data was returned.");
36 c.onError = (e) { 33 })
37 r.close(); 34 .catchError((e) {
38 }; 35 r.close();
36 });
39 } 37 }
40 } 38 }
41 39
42 main() { 40 main() {
43 Server server = new Server(); 41 Server.start().then((port) {
44 new Client(server.port); 42 new Client(port);
43 });
45 } 44 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_server_early_client_close_test.dart ('k') | tests/standalone/io/http_server_handler_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698