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

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

Issue 15814004: Don't report unuseful SocketIOExceptions on HttpServer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve test. Created 7 years, 7 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 | « tests/standalone/io/http_server_early_client_close_test.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_server_response_test.dart
diff --git a/tests/standalone/io/http_server_response_test.dart b/tests/standalone/io/http_server_response_test.dart
index d27dcc765f7535d76d8733c26629e08db2e3c350..0e75d349842007f1218de3408d11126bc08508c0 100644
--- a/tests/standalone/io/http_server_response_test.dart
+++ b/tests/standalone/io/http_server_response_test.dart
@@ -12,7 +12,9 @@ import "dart:async";
import "dart:io";
import "dart:typed_data";
-void testServerRequest(void handler(server, request), {int bytes}) {
+void testServerRequest(void handler(server, request),
+ {int bytes,
+ bool closeClient}) {
HttpServer.bind("127.0.0.1", 0).then((server) {
server.listen((request) {
handler(server, request);
@@ -26,8 +28,16 @@ void testServerRequest(void handler(server, request), {int bytes}) {
.then((request) => request.close())
.then((response) {
int received = 0;
- response.listen(
- (data) => received += data.length,
+ var subscription;
+ subscription = response.listen(
+ (data) {
+ if (closeClient == true) {
+ subscription.cancel();
+ client.close();
+ } else {
+ received += data.length;
+ }
+ },
onDone: () {
if (bytes != null) Expect.equals(received, bytes);
client.close();
@@ -42,6 +52,7 @@ void testServerRequest(void handler(server, request), {int bytes}) {
});
}
+
void testResponseDone() {
testServerRequest((server, request) {
request.response.close();
@@ -67,6 +78,7 @@ void testResponseDone() {
});
}
+
void testResponseAddStream() {
int bytes = new File(new Options().script).lengthSync();
@@ -114,6 +126,70 @@ void testResponseAddStream() {
});
}
+
+void testResponseAddStreamClosed() {
+ testServerRequest((server, request) {
+ request.response.addStream(new File(new Options().script).openRead())
+ .then((response) {
+ response.close();
+ response.done.then((_) => server.close());
+ });
+ }, closeClient: true);
+
+ testServerRequest((server, request) {
+ int count = 0;
+ write() {
+ request.response.addStream(new File(new Options().script).openRead())
+ .then((response) {
+ request.response.write("sync data");
+ count++;
+ if (count < 1000) {
+ write();
+ } else {
+ response.close();
+ response.done.then((_) => server.close());
+ }
+ });
+ }
+ write();
+ }, closeClient: true);
+}
+
+
+void testResponseAddClosed() {
+ testServerRequest((server, request) {
+ request.response.add(new File(new Options().script).readAsBytesSync());
+ request.response.close();
+ request.response.done.then((_) => server.close());
+ }, closeClient: true);
+
+ testServerRequest((server, request) {
+ for (int i = 0; i < 1000; i++) {
+ request.response.add(new File(new Options().script).readAsBytesSync());
+ }
+ request.response.close();
+ request.response.done.then((_) => server.close());
+ }, closeClient: true);
+
+ testServerRequest((server, request) {
+ int count = 0;
+ write() {
+ request.response.add(new File(new Options().script).readAsBytesSync());
+ Timer.run(() {
+ count++;
+ if (count < 1000) {
+ write();
+ } else {
+ request.response.close();
+ request. response.done.then((_) => server.close());
+ }
+ });
+ }
+ write();
+ }, closeClient: true);
+}
+
+
void testBadResponseAdd() {
testServerRequest((server, request) {
request.response.contentLength = 0;
@@ -146,6 +222,7 @@ void testBadResponseAdd() {
});
}
+
void testBadResponseClose() {
testServerRequest((server, request) {
request.response.contentLength = 5;
@@ -165,9 +242,12 @@ void testBadResponseClose() {
});
}
+
void main() {
testResponseDone();
testResponseAddStream();
+ testResponseAddStreamClosed();
+ testResponseAddClosed();
testBadResponseAdd();
testBadResponseClose();
}
« no previous file with comments | « tests/standalone/io/http_server_early_client_close_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698