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

Side by Side Diff: pkg/http_multi_server/test/http_multi_server_test.dart

Issue 375113002: Swallow errors in subscriptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library http_multi_server.test; 5 library http_multi_server.test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:http/http.dart' as http; 10 import 'package:http/http.dart' as http;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 test("listens on all localhost interfaces", () { 102 test("listens on all localhost interfaces", () {
103 server.listen((request) { 103 server.listen((request) {
104 request.response.write("got request"); 104 request.response.write("got request");
105 request.response.close(); 105 request.response.close();
106 }); 106 });
107 107
108 expect(http.read("http://127.0.0.1:${server.port}/"), 108 expect(http.read("http://127.0.0.1:${server.port}/"),
109 completion(equals("got request"))); 109 completion(equals("got request")));
110 110
111 return supportsIpV6.then((supportsIpV6) { 111 return _supportsIpV6.then((supportsIpV6) {
112 if (!supportsIpV6) return; 112 if (!supportsIpV6) return;
113 expect(http.read("http://[::1]:${server.port}/"), 113 expect(http.read("http://[::1]:${server.port}/"),
114 completion(equals("got request"))); 114 completion(equals("got request")));
115 }); 115 });
116 }); 116 });
117 }); 117 });
118 } 118 }
119 119
120 /// A cache for [supportsIpV6].
121 bool _supportsIpV6Cache;
122
123 /// Returns whether this computer supports binding to IPv6 addresses.
124 Future<bool> get _supportsIpV6 {
125 if (_supportsIpV6Cache != null) return new Future.value(_supportsIpV6Cache);
126
127 return ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0).then((socket) {
128 _supportsIpV6Cache = true;
129 socket.close();
130 return true;
131 }).catchError((error) {
132 if (error is! SocketException) throw error;
133 _supportsIpV6Cache = false;
134 return false;
135 });
136 }
nweiz 2014/07/09 02:02:01 I'm kind of uncomfortable about using different IP
137
120 /// Makes a GET request to the root of [server] and returns the response. 138 /// Makes a GET request to the root of [server] and returns the response.
121 Future<http.Response> _get(HttpServer server) => http.get(_urlFor(server)); 139 Future<http.Response> _get(HttpServer server) => http.get(_urlFor(server));
122 140
123 /// Makes a GET request to the root of [server] and returns the response body. 141 /// Makes a GET request to the root of [server] and returns the response body.
124 Future<String> _read(HttpServer server) => http.read(_urlFor(server)); 142 Future<String> _read(HttpServer server) => http.read(_urlFor(server));
125 143
126 /// Returns the URL for the root of [server]. 144 /// Returns the URL for the root of [server].
127 String _urlFor(HttpServer server) => 145 String _urlFor(HttpServer server) =>
128 "http://${server.address.host}:${server.port}/"; 146 "http://${server.address.host}:${server.port}/";
OLDNEW
« pkg/http_multi_server/lib/src/utils.dart ('K') | « pkg/http_multi_server/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698