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

Unified Diff: tests/standalone/src/io/HttpServerEarlyClientCloseTest.dart

Issue 9965008: Updated the early close test, to use a Socket that we can close at any time. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/io/HttpServerEarlyClientCloseTest.dart
===================================================================
--- tests/standalone/src/io/HttpServerEarlyClientCloseTest.dart (revision 0)
+++ tests/standalone/src/io/HttpServerEarlyClientCloseTest.dart (revision 0)
@@ -0,0 +1,89 @@
+#import("dart:io");
+#import("dart:isolate");
+
+void sendData(List<int> data, int port) {
+ Socket socket = new Socket("127.0.0.1", port);
+ socket.onConnect = () {
+ socket.onData = () {
+ Expect.fail("No data response was expected");
+ };
+ socket.outputStream.onNoPendingWrites = () {
+ socket.close(false);
+ };
+ socket.outputStream.write(data);
+ };
+}
+
+class EarlyCloseTest {
+ EarlyCloseTest(Object this.data,
+ String this.exception,
+ [bool this.expectRequest = false]);
+
+ Future execute(HttpServer server) {
+ Completer c = new Completer();
+
+ bool calledOnRequest = false;
+ server.onRequest = (HttpRequest request, HttpResponse response) {
+ Expect.isTrue(expectRequest);
+ Expect.isFalse(calledOnRequest, "onRequest called multiple times");
+ calledOnRequest = true;
+ };
+ ReceivePort port = new ReceivePort();
+ server.onError = (Exception error) {
+ Expect.equals(exception, error.message);
+ calledOnRequest = true; // onRequest is not allowed after onError.
+ port.close();
+ c.complete(null);
+ };
+
+ List<int> d;
+ if (data is List<int>) d = data;
+ if (data is String) d = data.charCodes();
+ if (d == null) Expect.fail("Invalid data");
+ sendData(d, server.port);
+
+ return c.future;
+ }
+
+ final Object data;
+ final String exception;
+ final bool expectRequest;
+}
+
+void testEarlyClose() {
+ List<EarlyCloseTest> tests = new List<EarlyCloseTest>();
+ void add(Object data, String exception, [bool expectRequest = false]) {
+ tests.add(new EarlyCloseTest(data, exception, expectRequest));
+ }
+ // The empty packet is valid.
+
+ // Close while sending header
+ add("G", "Connection closed before header was received");
+ add("GET /", "Failed to parse HTTP");
+ add("GET / HTTP/1.1", "Failed to parse HTTP");
+ add("GET / HTTP/1.1\r\n", "Failed to parse HTTP");
+
+ // Close while sending content
+ add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n",
+ "Failed to parse HTTP",
+ expectRequest: true);
+ add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n1",
+ "Failed to parse HTTP",
+ expectRequest: true);
+
+
+ HttpServer server = new HttpServer();
+ server.listen("127.0.0.1", 0);
+ void runTest(Iterator it) {
+ if (it.hasNext()) {
+ it.next().execute(server).then((_) => runTest(it));
+ } else {
+ server.close();
+ }
+ }
+ runTest(tests.iterator());
+}
+
+void main() {
+ testEarlyClose();
+}
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698