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

Unified Diff: tests/standalone/src/io/HttpServerEarlyCloseTest.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/HttpServerEarlyCloseTest.dart
===================================================================
--- tests/standalone/src/io/HttpServerEarlyCloseTest.dart (revision 6022)
+++ tests/standalone/src/io/HttpServerEarlyCloseTest.dart (working copy)
@@ -1,39 +1,93 @@
#import("dart:io");
#import("dart:isolate");
-class Server {
- Server() {
- HttpServer server = new HttpServer();
- server.listen("127.0.0.1", 0);
- port = server.port;
- server.onRequest = (HttpRequest request, HttpResponse response) {
- new Timer(100, (timer) => server.close());
+Future sendData(List<int> data, int port) {
+ Completer c = new Completer();
+ Socket socket = new Socket("127.0.0.1", port);
+ socket.onConnect = () {
+ socket.onData = () {
+ Expect.fail("No data response was expected");
};
- server.onError = (Object exception) {
- Expect.fail("Close should not give an error.");
+ socket.outputStream.onNoPendingWrites = () {
+ socket.close(false);
+ c.complete(null);
};
- }
- int port;
+ socket.outputStream.write(data);
+ };
+ return c.future;
}
-class Client {
- Client(int port) {
- ReceivePort r = new ReceivePort();
- HttpClient client = new HttpClient();
- HttpClientConnection c = client.get("127.0.0.1", port, "/");
- c.onRequest = (HttpClientRequest request) {
- request.outputStream.close();
+class EarlyCloseTest {
+ EarlyCloseTest(Object this.data,
+ String this.exception,
+ [bool this.expectRequest = false]);
+
+ Future execute(HttpServer server) {
+ Completer c = new Completer();
+
+ server.onRequest = (HttpRequest request, HttpResponse response) {
Søren Gjesse 2012/03/30 08:56:53 Maybe check that each onRequest function are only
Anders Johnsen 2012/03/30 09:29:27 Done.
+ Expect.isTrue(expectRequest);
};
- c.onResponse = (HttpClientResponse response) {
- Expect.fail("Response should not be given, as not data was returned.");
+ ReceivePort port = new ReceivePort();
+ server.onError = (Exception error) {
Søren Gjesse 2012/03/30 08:56:53 Maybe set onRequest to a failure function here, ju
Anders Johnsen 2012/03/30 09:29:27 Ahh yes, very nice catch!
+ Expect.equals(exception, error.message);
+ port.close();
+ c.complete(null);
};
- c.onError = (Object exception) {
- r.close();
- };
+
+ 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).then((_) {
Søren Gjesse 2012/03/30 08:56:53 We don't want timed tests, as they are bound to b
Anders Johnsen 2012/03/30 09:29:27 Done.
+ // The error is to be expected within 100 ms.
+ new Timer(100, (_) {
+ Expect.isTrue(c.future.isComplete, "onError have not been signaled");
+ });
+ });
+
+ return c.future;
}
+
+ final Object data;
+ final String exception;
+ final bool expectRequest;
}
-main() {
- Server server = new Server();
- new Client(server.port);
+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