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

Unified Diff: tests/standalone/io/http_bind_test.dart

Issue 925403002: Add the shared flag to HttpServer as well (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/io/socket.dart ('K') | « sdk/lib/io/socket.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_bind_test.dart
diff --git a/tests/standalone/io/http_bind_test.dart b/tests/standalone/io/http_bind_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2d67d1cd062d5794512f1155729231545d96e96f
--- /dev/null
+++ b/tests/standalone/io/http_bind_test.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:io';
+import 'dart:convert';
+
+import 'package:async_helper/async_helper.dart';
+import 'package:expect/expect.dart';
+
+testBindShared(String host, bool v6Only) async {
+ asyncStart();
+
+ // Sent a single request using a new HttpClient to ensure a new TCP
+ // connnection is used.
+ Future singleRequest(host, port) async {
+ var client = new HttpClient();
+ var request = await client.open('GET', host, port, '/');
+ var response = await request.close();
kustermann 2015/02/17 11:30:56 Maybe use a specific status code, to ensure we got
Søren Gjesse 2015/02/17 12:53:11 Done.
+ await response.drain();
+ client.close(force: true);
+ }
+
+ Completer server1Request = new Completer();
+ Completer server2Request = new Completer();
+
+ var server1 = await HttpServer.bind(host, 0, v6Only: v6Only, shared: true);
+ var port = server1.port;
+ Expect.isTrue(port > 0);
+
+ var server2 = await HttpServer.bind(host, port, v6Only: v6Only, shared: true);
+ Expect.equals(server1.address.address, server2.address.address);
+ Expect.equals(port, server2.port);
+
+ server1.listen((request) async {
+ server1Request.complete();
+ await request.response.close();
kustermann 2015/02/17 11:30:56 You could remove the "async " and "await" here, si
Søren Gjesse 2015/02/17 12:53:11 Done.
+ });
+
+ await singleRequest(host, port);
+ await server1.close();
+
+ server2.listen((request) async {
+ server2Request.complete();
+ await request.response.close();
kustermann 2015/02/17 11:30:56 ditto
Søren Gjesse 2015/02/17 12:53:11 Done.
+ });
+
+ await singleRequest(host, port);
+ await server2.close();
+
+ await server1Request.future;
+ await server2Request.future;
+
+ asyncEnd();
+}
+
+void main() {
+ for (var host in ['127.0.0.1', '::1']) {
+ testBindShared(host, false);
+ testBindShared(host, true);
kustermann 2015/02/17 11:30:56 This translates to 1 testBindShared('127.0.0.1',
Søren Gjesse 2015/02/17 12:53:11 In that case v6Only is ignored. Not sure that is t
+ }
+}
« sdk/lib/io/socket.dart ('K') | « sdk/lib/io/socket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698