| OLD | NEW |
| 1 #import("dart:io"); | 1 #import("dart:io"); |
| 2 #import("dart:isolate"); | 2 #import("dart:isolate"); |
| 3 | 3 |
| 4 void sendData(List<int> data, int port) { | 4 void sendData(List<int> data, int port) { |
| 5 Socket socket = new Socket("127.0.0.1", port); | 5 Socket socket = new Socket("127.0.0.1", port); |
| 6 socket.onConnect = () { | 6 socket.onConnect = () { |
| 7 socket.onData = () { | 7 socket.onData = () { |
| 8 Expect.fail("No data response was expected"); | 8 Expect.fail("No data response was expected"); |
| 9 }; | 9 }; |
| 10 socket.outputStream.onNoPendingWrites = () { | 10 socket.outputStream.onNoPendingWrites = () { |
| 11 socket.close(false); | 11 socket.close(false); |
| 12 }; | 12 }; |
| 13 socket.outputStream.write(data); | 13 socket.outputStream.write(data); |
| 14 }; | 14 }; |
| 15 } | 15 } |
| 16 | 16 |
| 17 class EarlyCloseTest { | 17 class EarlyCloseTest { |
| 18 EarlyCloseTest(Object this.data, | 18 EarlyCloseTest(Object this.data, |
| 19 String this.exception, | 19 String this.exception, |
| 20 [bool this.expectRequest = false]); | 20 [bool this.expectRequest = false]); |
| 21 | 21 |
| 22 Future execute(HttpServer server) { | 22 Future execute(HttpServer server) { |
| 23 Completer c = new Completer(); | 23 Completer c = new Completer(); |
| 24 | 24 |
| 25 bool calledOnRequest = false; | 25 bool calledOnRequest = false; |
| 26 bool calledOnError = false; | 26 bool calledOnError = false; |
| 27 server.onRequest = (HttpRequest request, HttpResponse response) { | 27 server.defaultRequestHandler = |
| 28 Expect.isTrue(expectRequest); | 28 (HttpRequest request, HttpResponse response) { |
| 29 Expect.isFalse(calledOnError); | 29 Expect.isTrue(expectRequest); |
| 30 Expect.isFalse(calledOnRequest, "onRequest called multiple times"); | 30 Expect.isFalse(calledOnError); |
| 31 calledOnRequest = true; | 31 Expect.isFalse(calledOnRequest, "onRequest called multiple times"); |
| 32 }; | 32 calledOnRequest = true; |
| 33 }; |
| 33 ReceivePort port = new ReceivePort(); | 34 ReceivePort port = new ReceivePort(); |
| 34 server.onError = (Exception error) { | 35 server.onError = (Exception error) { |
| 35 Expect.isFalse(calledOnError); | 36 Expect.isFalse(calledOnError); |
| 36 Expect.equals(exception, error.message); | 37 Expect.equals(exception, error.message); |
| 37 Expect.equals(expectRequest, calledOnRequest); | 38 Expect.equals(expectRequest, calledOnRequest); |
| 38 calledOnError = true; | 39 calledOnError = true; |
| 39 port.close(); | 40 port.close(); |
| 40 c.complete(null); | 41 c.complete(null); |
| 41 }; | 42 }; |
| 42 | 43 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } else { | 85 } else { |
| 85 server.close(); | 86 server.close(); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 runTest(tests.iterator()); | 89 runTest(tests.iterator()); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void main() { | 92 void main() { |
| 92 testEarlyClose(); | 93 testEarlyClose(); |
| 93 } | 94 } |
| OLD | NEW |