OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 request.response.close(); | 44 request.response.close(); |
45 }); | 45 }); |
46 }); | 46 }); |
47 return server; | 47 return server; |
48 }); | 48 }); |
49 } | 49 } |
50 | 50 |
51 Future test(String certType, String password) { | 51 Future test(String certType, String password) { |
52 List<int> body = <int>[]; | 52 List<int> body = <int>[]; |
| 53 Completer completer = new Completer(); |
53 startServer(certType, password).then((server) { | 54 startServer(certType, password).then((server) { |
54 SecureSocket.connect( | 55 SecureSocket.connect( |
55 "localhost", server.port, context: clientContext(certType, password)) | 56 "localhost", server.port, context: clientContext(certType, password)) |
56 .then((socket) { | 57 .then((socket) { |
57 socket.write("GET / HTTP/1.0\r\nHost: localhost\r\n\r\n"); | 58 socket.write("GET / HTTP/1.0\r\nHost: localhost\r\n\r\n"); |
58 socket.close(); | 59 socket.close(); |
59 socket.listen( | 60 socket.listen( |
60 (List<int> data) { | 61 (List<int> data) { |
61 body.addAll(data); | 62 body.addAll(data); |
62 }, | 63 }, |
63 onDone: () { | 64 onDone: () { |
64 Expect.isTrue(body.length > 100, "$body\n${body.length}"); | 65 Expect.isTrue(body.length > 100, "$body\n${body.length}"); |
65 Expect.equals(72, body[0]); | 66 Expect.equals(72, body[0]); |
66 Expect.equals(9, body[body.length - 1]); | 67 Expect.equals(9, body[body.length - 1]); |
67 server.close(); | 68 server.close(); |
| 69 completer.complete(null); |
68 }, | 70 }, |
69 onError: (e, trace) { | 71 onError: (e, trace) { |
70 String msg = "Unexpected error $e"; | 72 String msg = "Unexpected error $e"; |
71 if (trace != null) msg += "\nStackTrace: $trace"; | 73 if (trace != null) msg += "\nStackTrace: $trace"; |
72 Expect.fail(msg); | 74 Expect.fail(msg); |
| 75 completer.complete(null); |
73 }); | 76 }); |
74 }); | 77 }); |
75 }); | 78 }); |
| 79 return completer.future; |
76 } | 80 } |
77 | 81 |
78 main() async { | 82 main() async { |
79 asyncStart(); | 83 asyncStart(); |
80 await test('pem', 'dartdart'); | 84 await test('pem', 'dartdart'); |
81 await test('p12', 'dartdart'); | 85 await test('p12', 'dartdart'); |
82 asyncEnd(); | 86 asyncEnd(); |
83 } | 87 } |
OLD | NEW |