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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "package:expect/expect.dart";
11 import "dart:async";
12 import "dart:io";
13
14 void testSimpleDeadline(int connections) {
15 HttpServer.bind('localhost', 0).then((server) {
16 server.listen((request) {
17 request.response.deadline = const Duration(seconds: 1);
18 request.response.write("stuff");
19 request.response.close();
20 });
21
22 var futures = [];
23 var client = new HttpClient();
24 for (int i = 0; i < connections; i++) {
25 futures.add(client.get('localhost', server.port, '/')
26 .then((request) => request.close())
27 .then((response) => response.drain()));
28 }
29 Future.wait(futures).then((_) => server.close());
30 });
31 }
32
33 void testExceedDeadline(int connections) {
34 HttpServer.bind('localhost', 0).then((server) {
35 server.listen((request) {
36 request.response.deadline = const Duration(milliseconds: 100);
37 request.response.contentLength = 10000;
38 request.response.write("stuff");
39 });
40
41 var futures = [];
42 var client = new HttpClient();
43 for (int i = 0; i < connections; i++) {
44 futures.add(client.get('localhost', server.port, '/')
45 .then((request) => request.close())
46 .then((response) {
47 return response.drain().then((_) {
48 Expect.fail("Expected error");
49 }, onError: (e) {
50 // Expect error.
51 });
52 }));
53 }
54 Future.wait(futures).then((_) => server.close());
55 });
56 }
57
58 void testDeadlineAndDetach(int connections) {
59 HttpServer.bind('localhost', 0).then((server) {
60 server.listen((request) {
61 request.response.deadline = const Duration(milliseconds: 0);
62 request.response.contentLength = 5;
63 request.response.detachSocket().then((socket) {
64 new Timer(const Duration(milliseconds: 100), () {
65 socket.write('stuff');
66 socket.close();
67 });
68 });
69 });
70
71 var futures = [];
72 var client = new HttpClient();
73 for (int i = 0; i < connections; i++) {
74 futures.add(client.get('localhost', server.port, '/')
75 .then((request) => request.close())
76 .then((response) {
77 return response.fold(new BytesBuilder(), (b, d) => b..add(d))
78 .then((builder) {
79 Expect.equals('stuff',
80 new String.fromCharCodes(builder.takeBytes()));
81 });
82 }));
83 }
84 Future.wait(futures).then((_) => server.close());
85 });
86 }
87
88 void main() {
89 testSimpleDeadline(10);
90 testExceedDeadline(10);
91 testDeadlineAndDetach(10);
92 }
93
OLDNEW
« 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