Index: pkg/http_multi_server/test/http_multi_server_test.dart |
diff --git a/pkg/http_multi_server/test/http_multi_server_test.dart b/pkg/http_multi_server/test/http_multi_server_test.dart |
index a3d9062067bced9da28b8452eccec18c0212a906..0140ee7c8968c37947dd33ade9dd0e8b05016b66 100644 |
--- a/pkg/http_multi_server/test/http_multi_server_test.dart |
+++ b/pkg/http_multi_server/test/http_multi_server_test.dart |
@@ -108,7 +108,7 @@ void main() { |
expect(http.read("http://127.0.0.1:${server.port}/"), |
completion(equals("got request"))); |
- return supportsIpV6.then((supportsIpV6) { |
+ return _supportsIpV6.then((supportsIpV6) { |
if (!supportsIpV6) return; |
expect(http.read("http://[::1]:${server.port}/"), |
completion(equals("got request"))); |
@@ -117,6 +117,26 @@ void main() { |
}); |
} |
+/// A cache for [supportsIpV6]. |
+bool _supportsIpV6Cache; |
+ |
+// TODO(nweiz): This is known to be inaccurate on Windows machines with IPv6 |
+// disabled (issue 19815). Tests will fail on such machines. |
+/// Returns whether this computer supports binding to IPv6 addresses. |
+Future<bool> get _supportsIpV6 { |
+ if (_supportsIpV6Cache != null) return new Future.value(_supportsIpV6Cache); |
+ |
+ return ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0).then((socket) { |
+ _supportsIpV6Cache = true; |
+ socket.close(); |
+ return true; |
+ }).catchError((error) { |
+ if (error is! SocketException) throw error; |
+ _supportsIpV6Cache = false; |
+ return false; |
+ }); |
+} |
+ |
/// Makes a GET request to the root of [server] and returns the response. |
Future<http.Response> _get(HttpServer server) => http.get(_urlFor(server)); |