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

Side by Side Diff: tests/standalone/io/raw_secure_server_socket_test.dart

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 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
OLDNEW
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 "dart:async";
11 import "dart:io";
12
13 import "package:async_helper/async_helper.dart";
10 import "package:expect/expect.dart"; 14 import "package:expect/expect.dart";
11 import "package:path/path.dart"; 15 import "package:path/path.dart";
12 import "dart:async";
13 import "dart:io";
14 import "dart:isolate";
15 16
16 const HOST_NAME = "localhost"; 17 const HOST_NAME = "localhost";
17 const CERTIFICATE = "localhost_cert"; 18 const CERTIFICATE = "localhost_cert";
18 19
19 void testSimpleBind() { 20 void testSimpleBind() {
20 ReceivePort port = new ReceivePort(); 21 asyncStart();
21 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((s) { 22 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((s) {
22 Expect.isTrue(s.port > 0); 23 Expect.isTrue(s.port > 0);
23 s.close(); 24 s.close();
24 port.close(); 25 asyncEnd();
25 }); 26 });
26 } 27 }
27 28
28 void testInvalidBind() { 29 void testInvalidBind() {
29 int count = 0; 30 int count = 0;
30 ReceivePort port = new ReceivePort();
31 port.receive((_, __) { count++; if (count == 3) port.close(); });
32 31
33 // Bind to a unknown DNS name. 32 // Bind to a unknown DNS name.
33 asyncStart();
34 RawSecureServerSocket.bind("ko.faar.__hest__", 0, CERTIFICATE).then((_) { 34 RawSecureServerSocket.bind("ko.faar.__hest__", 0, CERTIFICATE).then((_) {
35 Expect.fail("Failure expected"); 35 Expect.fail("Failure expected");
36 }).catchError((error) { 36 }).catchError((error) {
37 Expect.isTrue(error is SocketException); 37 Expect.isTrue(error is SocketException);
38 port.toSendPort().send(1); 38 asyncEnd();
39 }); 39 });
40 40
41 // Bind to an unavaliable IP-address. 41 // Bind to an unavaliable IP-address.
42 asyncStart();
42 RawSecureServerSocket.bind("8.8.8.8", 0, CERTIFICATE).then((_) { 43 RawSecureServerSocket.bind("8.8.8.8", 0, CERTIFICATE).then((_) {
43 Expect.fail("Failure expected"); 44 Expect.fail("Failure expected");
44 }).catchError((error) { 45 }).catchError((error) {
45 Expect.isTrue(error is SocketException); 46 Expect.isTrue(error is SocketException);
46 port.toSendPort().send(1); 47 asyncEnd();
47 }); 48 });
48 49
49 // Bind to a port already in use. 50 // Bind to a port already in use.
51 asyncStart();
50 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((s) { 52 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((s) {
51 RawSecureServerSocket.bind(HOST_NAME, 53 RawSecureServerSocket.bind(HOST_NAME,
52 s.port, 54 s.port,
53 CERTIFICATE).then((t) { 55 CERTIFICATE).then((t) {
54 Expect.fail("Multiple listens on same port"); 56 Expect.fail("Multiple listens on same port");
55 s.close(); 57 s.close();
56 t.close(); 58 t.close();
57 port.toSendPort().send(1); 59 port.toSendPort().send(1);
58 }) 60 })
59 .catchError((error) { 61 .catchError((error) {
60 Expect.isTrue(error is SocketException); 62 Expect.isTrue(error is SocketException);
61 s.close(); 63 s.close();
62 port.toSendPort().send(1); 64 asyncEnd();
63 }); 65 });
64 }); 66 });
65 } 67 }
66 68
67 void testSimpleConnect(String certificate) { 69 void testSimpleConnect(String certificate) {
68 ReceivePort port = new ReceivePort(); 70 asyncStart();
69 RawSecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) { 71 RawSecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) {
70 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port); 72 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port);
71 server.listen((serverEnd) { 73 server.listen((serverEnd) {
72 clientEndFuture.then((clientEnd) { 74 clientEndFuture.then((clientEnd) {
73 clientEnd.shutdown(SocketDirection.SEND); 75 clientEnd.shutdown(SocketDirection.SEND);
74 serverEnd.shutdown(SocketDirection.SEND); 76 serverEnd.shutdown(SocketDirection.SEND);
75 server.close(); 77 server.close();
76 port.close(); 78 asyncEnd();
77 }); 79 });
78 }); 80 });
79 }); 81 });
80 } 82 }
81 83
82 void testSimpleConnectFail(String certificate, bool cancelOnError) { 84 void testSimpleConnectFail(String certificate, bool cancelOnError) {
83 ReceivePort port = new ReceivePort(); 85 asyncStart();
84 RawSecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) { 86 RawSecureServerSocket.bind(HOST_NAME, 0, certificate).then((server) {
85 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port) 87 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port)
86 .then((clientEnd) { 88 .then((clientEnd) {
87 Expect.fail("No client connection expected."); 89 Expect.fail("No client connection expected.");
88 }) 90 })
89 .catchError((error) { 91 .catchError((error) {
90 Expect.isTrue(error is SocketException || 92 Expect.isTrue(error is SocketException ||
91 error is HandshakeException); 93 error is HandshakeException);
92 }); 94 });
93 server.listen((serverEnd) { 95 server.listen((serverEnd) {
94 Expect.fail("No server connection expected."); 96 Expect.fail("No server connection expected.");
95 }, 97 },
96 onError: (error) { 98 onError: (error) {
97 Expect.isTrue(error is CertificateException); 99 Expect.isTrue(error is CertificateException);
98 clientEndFuture.then((_) { 100 clientEndFuture.then((_) {
99 if (!cancelOnError) server.close(); 101 if (!cancelOnError) server.close();
100 port.close(); 102 asyncEnd();
101 }); 103 });
102 }, 104 },
103 cancelOnError: cancelOnError); 105 cancelOnError: cancelOnError);
104 }); 106 });
105 } 107 }
106 108
107 void testServerListenAfterConnect() { 109 void testServerListenAfterConnect() {
108 ReceivePort port = new ReceivePort(); 110 asyncStart();
109 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((server) { 111 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((server) {
110 Expect.isTrue(server.port > 0); 112 Expect.isTrue(server.port > 0);
111 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port); 113 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port);
112 new Timer(const Duration(milliseconds: 500), () { 114 new Timer(const Duration(milliseconds: 500), () {
113 server.listen((serverEnd) { 115 server.listen((serverEnd) {
114 clientEndFuture.then((clientEnd) { 116 clientEndFuture.then((clientEnd) {
115 clientEnd.shutdown(SocketDirection.SEND); 117 clientEnd.shutdown(SocketDirection.SEND);
116 serverEnd.shutdown(SocketDirection.SEND); 118 serverEnd.shutdown(SocketDirection.SEND);
117 server.close(); 119 server.close();
118 port.close(); 120 asyncEnd();
119 }); 121 });
120 }); 122 });
121 }); 123 });
122 }); 124 });
123 } 125 }
124 126
125 // This test creates a server and a client connects. The client then 127 // This test creates a server and a client connects. The client then
126 // writes and the server echos. When the server has finished its echo 128 // writes and the server echos. When the server has finished its echo
127 // it half-closes. When the client gets the close event is closes 129 // it half-closes. When the client gets the close event is closes
128 // fully. 130 // fully.
(...skipping 28 matching lines...) Expand all
157 bool handshakeBeforeSecure, 159 bool handshakeBeforeSecure,
158 bool postponeSecure, 160 bool postponeSecure,
159 bool dropReads}) { 161 bool dropReads}) {
160 int clientReads = 0; 162 int clientReads = 0;
161 int serverReads = 0; 163 int serverReads = 0;
162 if (handshakeBeforeSecure == true && 164 if (handshakeBeforeSecure == true &&
163 (listenSecure == true || connectSecure == true)) { 165 (listenSecure == true || connectSecure == true)) {
164 Expect.fail("Invalid arguments to testSimpleReadWrite"); 166 Expect.fail("Invalid arguments to testSimpleReadWrite");
165 } 167 }
166 168
167 ReceivePort port = new ReceivePort(); 169 asyncStart();
168 170
169 const messageSize = 1000; 171 const messageSize = 1000;
170 const handshakeMessageSize = 100; 172 const handshakeMessageSize = 100;
171 173
172 List<int> createTestData() { 174 List<int> createTestData() {
173 List<int> data = new List<int>(messageSize); 175 List<int> data = new List<int>(messageSize);
174 for (int i = 0; i < messageSize; i++) { 176 for (int i = 0; i < messageSize; i++) {
175 data[i] = i & 0xff; 177 data[i] = i & 0xff;
176 } 178 }
177 return data; 179 return data;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 subscription: secure[0], 454 subscription: secure[0],
453 bufferedData: secure[1]).then((client) { 455 bufferedData: secure[1]).then((client) {
454 runServer(client).then((_) => server.close()); 456 runServer(client).then((_) => server.close());
455 }); 457 });
456 }); 458 });
457 } 459 }
458 }); 460 });
459 461
460 connectClient(server.port).then(runClient).then((socket) { 462 connectClient(server.port).then(runClient).then((socket) {
461 socket.close(); 463 socket.close();
462 port.close(); 464 asyncEnd();
463 }); 465 });
464 } 466 }
465 467
466 if (listenSecure) { 468 if (listenSecure) {
467 RawSecureServerSocket.bind( 469 RawSecureServerSocket.bind(
468 HOST_NAME, 0, CERTIFICATE).then(serverReady); 470 HOST_NAME, 0, CERTIFICATE).then(serverReady);
469 } else { 471 } else {
470 RawServerSocket.bind(HOST_NAME, 0).then(serverReady); 472 RawServerSocket.bind(HOST_NAME, 0).then(serverReady);
471 } 473 }
472 } 474 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 connectSecure: true, 521 connectSecure: true,
520 handshakeBeforeSecure: false, 522 handshakeBeforeSecure: false,
521 postponeSecure: false, 523 postponeSecure: false,
522 dropReads: true); 524 dropReads: true);
523 testSimpleReadWrite(listenSecure: false, 525 testSimpleReadWrite(listenSecure: false,
524 connectSecure: false, 526 connectSecure: false,
525 handshakeBeforeSecure: true, 527 handshakeBeforeSecure: true,
526 postponeSecure: true, 528 postponeSecure: true,
527 dropReads: true); 529 dropReads: true);
528 } 530 }
OLDNEW
« no previous file with comments | « tests/standalone/io/raw_secure_server_closing_test.dart ('k') | tests/standalone/io/raw_server_socket_cancel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698