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

Side by Side 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, 8 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 | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #import("dart:io");
2 #import("dart:isolate");
3
4 void sendData(List<int> data, int port) {
5 Socket socket = new Socket("127.0.0.1", port);
6 socket.onConnect = () {
7 socket.onData = () {
8 Expect.fail("No data response was expected");
9 };
10 socket.outputStream.onNoPendingWrites = () {
11 socket.close(false);
12 };
13 socket.outputStream.write(data);
14 };
15 }
16
17 class EarlyCloseTest {
18 EarlyCloseTest(Object this.data,
19 String this.exception,
20 [bool this.expectRequest = false]);
21
22 Future execute(HttpServer server) {
23 Completer c = new Completer();
24
25 bool calledOnRequest = false;
26 server.onRequest = (HttpRequest request, HttpResponse response) {
27 Expect.isTrue(expectRequest);
28 Expect.isFalse(calledOnRequest, "onRequest called multiple times");
29 calledOnRequest = true;
30 };
31 ReceivePort port = new ReceivePort();
32 server.onError = (Exception error) {
33 Expect.equals(exception, error.message);
34 calledOnRequest = true; // onRequest is not allowed after onError.
35 port.close();
36 c.complete(null);
37 };
38
39 List<int> d;
40 if (data is List<int>) d = data;
41 if (data is String) d = data.charCodes();
42 if (d == null) Expect.fail("Invalid data");
43 sendData(d, server.port);
44
45 return c.future;
46 }
47
48 final Object data;
49 final String exception;
50 final bool expectRequest;
51 }
52
53 void testEarlyClose() {
54 List<EarlyCloseTest> tests = new List<EarlyCloseTest>();
55 void add(Object data, String exception, [bool expectRequest = false]) {
56 tests.add(new EarlyCloseTest(data, exception, expectRequest));
57 }
58 // The empty packet is valid.
59
60 // Close while sending header
61 add("G", "Connection closed before header was received");
62 add("GET /", "Failed to parse HTTP");
63 add("GET / HTTP/1.1", "Failed to parse HTTP");
64 add("GET / HTTP/1.1\r\n", "Failed to parse HTTP");
65
66 // Close while sending content
67 add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n",
68 "Failed to parse HTTP",
69 expectRequest: true);
70 add("GET / HTTP/1.1\r\nContent-Length: 100\r\n\r\n1",
71 "Failed to parse HTTP",
72 expectRequest: true);
73
74
75 HttpServer server = new HttpServer();
76 server.listen("127.0.0.1", 0);
77 void runTest(Iterator it) {
78 if (it.hasNext()) {
79 it.next().execute(server).then((_) => runTest(it));
80 } else {
81 server.close();
82 }
83 }
84 runTest(tests.iterator());
85 }
86
87 void main() {
88 testEarlyClose();
89 }
OLDNEW
« 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