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

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

Issue 19668013: Add 'deadline' to HttpResponse, making it possible to give a max duration for the liveness of the r… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up timers. Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http_impl.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_response_deadline_test.dart
diff --git a/tests/standalone/io/http_response_deadline_test.dart b/tests/standalone/io/http_response_deadline_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5964b61282e0ab322b81805d5958a63712837753
--- /dev/null
+++ b/tests/standalone/io/http_response_deadline_test.dart
@@ -0,0 +1,93 @@
+// 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.
+//
+// VMOptions=
+// VMOptions=--short_socket_read
+// VMOptions=--short_socket_write
+// VMOptions=--short_socket_read --short_socket_write
+
+import "package:expect/expect.dart";
+import "dart:async";
+import "dart:io";
+
+void testSimpleDeadline(int connections) {
+ HttpServer.bind('localhost', 0).then((server) {
+ server.listen((request) {
+ request.response.deadline = const Duration(seconds: 1);
+ request.response.write("stuff");
+ request.response.close();
+ });
+
+ var futures = [];
+ var client = new HttpClient();
+ for (int i = 0; i < connections; i++) {
+ futures.add(client.get('localhost', server.port, '/')
+ .then((request) => request.close())
+ .then((response) => response.drain()));
+ }
+ Future.wait(futures).then((_) => server.close());
+ });
+}
+
+void testExceedDeadline(int connections) {
+ HttpServer.bind('localhost', 0).then((server) {
+ server.listen((request) {
+ request.response.deadline = const Duration(milliseconds: 100);
+ request.response.contentLength = 10000;
+ request.response.write("stuff");
+ });
+
+ var futures = [];
+ var client = new HttpClient();
+ for (int i = 0; i < connections; i++) {
+ futures.add(client.get('localhost', server.port, '/')
+ .then((request) => request.close())
+ .then((response) {
+ return response.drain().then((_) {
+ Expect.fail("Expected error");
+ }, onError: (e) {
+ // Expect error.
+ });
+ }));
+ }
+ Future.wait(futures).then((_) => server.close());
+ });
+}
+
+void testDeadlineAndDetach(int connections) {
+ HttpServer.bind('localhost', 0).then((server) {
+ server.listen((request) {
+ request.response.deadline = const Duration(milliseconds: 0);
+ request.response.contentLength = 5;
+ request.response.detachSocket().then((socket) {
+ new Timer(const Duration(milliseconds: 100), () {
+ socket.write('stuff');
+ socket.close();
+ });
+ });
+ });
+
+ var futures = [];
+ var client = new HttpClient();
+ for (int i = 0; i < connections; i++) {
+ futures.add(client.get('localhost', server.port, '/')
+ .then((request) => request.close())
+ .then((response) {
+ return response.fold(new BytesBuilder(), (b, d) => b..add(d))
+ .then((builder) {
+ Expect.equals('stuff',
+ new String.fromCharCodes(builder.takeBytes()));
+ });
+ }));
+ }
+ Future.wait(futures).then((_) => server.close());
+ });
+}
+
+void main() {
+ testSimpleDeadline(10);
+ testExceedDeadline(10);
+ testDeadlineAndDetach(10);
+}
+
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698