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

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

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 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) 2013, the Dart project authors. Please see the AUTHORS file 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 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 "package:expect/expect.dart";
6 import "dart:async"; 5 import "dart:async";
7 import "dart:io"; 6 import "dart:io";
8 import "dart:isolate"; 7
8 import "package:async_helper/async_helper.dart";
9 import "package:expect/expect.dart";
9 10
10 void testListenOn() { 11 void testListenOn() {
11 ServerSocket socket; 12 ServerSocket socket;
12 HttpServer server; 13 HttpServer server;
13 14
14 void test(void onDone()) { 15 void test(void onDone()) {
15
16 Expect.equals(socket.port, server.port); 16 Expect.equals(socket.port, server.port);
17 17
18 ReceivePort clientPort = new ReceivePort();
19 HttpClient client = new HttpClient(); 18 HttpClient client = new HttpClient();
20 client.get("127.0.0.1", socket.port, "/") 19 client.get("127.0.0.1", socket.port, "/")
21 .then((request) { 20 .then((request) {
22 return request.close(); 21 return request.close();
23 }) 22 })
24 .then((response) { 23 .then((response) {
25 response.listen( 24 response.listen(
26 (_) {}, 25 (_) {},
27 onDone: () { 26 onDone: () {
28 client.close(); 27 client.close();
29 clientPort.close();
30 onDone(); 28 onDone();
31 }); 29 });
32 }) 30 })
33 .catchError((e) { 31 .catchError((e) {
34 String msg = "Unexpected error in Http Client: $e"; 32 String msg = "Unexpected error in Http Client: $e";
35 var trace = getAttachedStackTrace(e); 33 var trace = getAttachedStackTrace(e);
36 if (trace != null) msg += "\nStackTrace: $trace"; 34 if (trace != null) msg += "\nStackTrace: $trace";
37 Expect.fail(msg); 35 Expect.fail(msg);
38 }); 36 });
39 } 37 }
40 38
41 // Test two connection after each other. 39 // Test two connection after each other.
40 asyncStart();
42 ServerSocket.bind("127.0.0.1", 0).then((s) { 41 ServerSocket.bind("127.0.0.1", 0).then((s) {
43 socket = s; 42 socket = s;
44 server = new HttpServer.listenOn(socket); 43 server = new HttpServer.listenOn(socket);
45 ReceivePort serverPort = new ReceivePort();
46 server.listen((HttpRequest request) { 44 server.listen((HttpRequest request) {
47 request.listen( 45 request.listen(
48 (_) {}, 46 (_) {},
49 onDone: () { 47 onDone: () => request.response.close());
50 request.response.close();
51 serverPort.close();
52 });
53 }); 48 });
54 49
55 test(() { 50 test(() {
56 test(() { 51 test(() {
57 server.close(); 52 server.close();
58 Expect.throws(() => server.port); 53 Expect.throws(() => server.port);
59 socket.close(); 54 socket.close();
55 asyncEnd();
60 }); 56 });
61 }); 57 });
62 }); 58 });
63 } 59 }
64 60
65 void main() { 61 void main() {
66 testListenOn(); 62 testListenOn();
67 } 63 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_reuse_server_port_test.dart ('k') | tests/standalone/io/https_client_certificate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698