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

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

Issue 14640008: Change the signature for all network bind calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments by whesse@ Created 7 years, 7 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 "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 import "dart:async"; 11 import "dart:async";
12 import "dart:io"; 12 import "dart:io";
13 import "dart:isolate"; 13 import "dart:isolate";
14 14
15 const HOST_NAME = "localhost"; 15 const HOST_NAME = "localhost";
16 const CERTIFICATE = "localhost_cert"; 16 const CERTIFICATE = "localhost_cert";
17 17
18 void testCloseOneEnd(String toClose) { 18 void testCloseOneEnd(String toClose) {
19 ReceivePort port = new ReceivePort(); 19 ReceivePort port = new ReceivePort();
20 Completer serverDone = new Completer(); 20 Completer serverDone = new Completer();
21 Completer serverEndDone = new Completer(); 21 Completer serverEndDone = new Completer();
22 Completer clientEndDone = new Completer(); 22 Completer clientEndDone = new Completer();
23 Future.wait([serverDone.future, serverEndDone.future, clientEndDone.future]) 23 Future.wait([serverDone.future, serverEndDone.future, clientEndDone.future])
24 .then((_) { 24 .then((_) {
25 port.close(); 25 port.close();
26 }); 26 });
27 RawSecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 27 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((server) {
28 server.listen((serverConnection) { 28 server.listen((serverConnection) {
29 serverConnection.listen((event) { 29 serverConnection.listen((event) {
30 if (toClose == "server" || event == RawSocketEvent.READ_CLOSED) { 30 if (toClose == "server" || event == RawSocketEvent.READ_CLOSED) {
31 serverConnection.shutdown(SocketDirection.SEND); 31 serverConnection.shutdown(SocketDirection.SEND);
32 } 32 }
33 }, 33 },
34 onDone: () { 34 onDone: () {
35 serverEndDone.complete(null); 35 serverEndDone.complete(null);
36 }); 36 });
37 }, 37 },
38 onDone: () { 38 onDone: () {
39 serverDone.complete(null); 39 serverDone.complete(null);
40 }); 40 });
41 RawSecureSocket.connect(HOST_NAME, server.port).then((clientConnection) { 41 RawSecureSocket.connect(HOST_NAME, server.port).then((clientConnection) {
42 clientConnection.listen((event){ 42 clientConnection.listen((event){
43 if (toClose == "client" || event == RawSocketEvent.READ_CLOSED) { 43 if (toClose == "client" || event == RawSocketEvent.READ_CLOSED) {
44 clientConnection.shutdown(SocketDirection.SEND); 44 clientConnection.shutdown(SocketDirection.SEND);
45 } 45 }
46 }, 46 },
47 onDone: () { 47 onDone: () {
48 clientEndDone.complete(null); 48 clientEndDone.complete(null);
49 server.close(); 49 server.close();
50 }); 50 });
51 }); 51 });
52 }); 52 });
53 } 53 }
54 54
55 void testCloseBothEnds() { 55 void testCloseBothEnds() {
56 ReceivePort port = new ReceivePort(); 56 ReceivePort port = new ReceivePort();
57 RawSecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 57 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((server) {
58 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port); 58 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port);
59 server.listen((serverEnd) { 59 server.listen((serverEnd) {
60 clientEndFuture.then((clientEnd) { 60 clientEndFuture.then((clientEnd) {
61 clientEnd.close(); 61 clientEnd.close();
62 serverEnd.close(); 62 serverEnd.close();
63 server.close(); 63 server.close();
64 port.close(); 64 port.close();
65 }); 65 });
66 }); 66 });
67 }); 67 });
68 } 68 }
69 69
70 testPauseServerSocket() { 70 testPauseServerSocket() {
71 const int socketCount = 10; 71 const int socketCount = 10;
72 var acceptCount = 0; 72 var acceptCount = 0;
73 var resumed = false; 73 var resumed = false;
74 74
75 ReceivePort port = new ReceivePort(); 75 ReceivePort port = new ReceivePort();
76 76
77 RawSecureServerSocket.bind(HOST_NAME, 77 RawSecureServerSocket.bind(HOST_NAME,
78 0, 78 0,
79 2 * socketCount, 79 CERTIFICATE,
80 CERTIFICATE).then((server) { 80 backlog: 2 * socketCount).then((server) {
81 Expect.isTrue(server.port > 0); 81 Expect.isTrue(server.port > 0);
82 var subscription; 82 var subscription;
83 subscription = server.listen((connection) { 83 subscription = server.listen((connection) {
84 Expect.isTrue(resumed); 84 Expect.isTrue(resumed);
85 connection.shutdown(SocketDirection.SEND); 85 connection.shutdown(SocketDirection.SEND);
86 if (++acceptCount == 2 * socketCount) { 86 if (++acceptCount == 2 * socketCount) {
87 server.close(); 87 server.close();
88 port.close(); 88 port.close();
89 } 89 }
90 }); 90 });
(...skipping 18 matching lines...) Expand all
109 } 109 }
110 }); 110 });
111 }); 111 });
112 } 112 }
113 113
114 testCloseServer() { 114 testCloseServer() {
115 const int socketCount = 3; 115 const int socketCount = 3;
116 ReceivePort port = new ReceivePort(); 116 ReceivePort port = new ReceivePort();
117 List ends = []; 117 List ends = [];
118 118
119 RawSecureServerSocket.bind(HOST_NAME, 0, 15, CERTIFICATE).then((server) { 119 RawSecureServerSocket.bind(HOST_NAME, 0, CERTIFICATE).then((server) {
120 Expect.isTrue(server.port > 0); 120 Expect.isTrue(server.port > 0);
121 void checkDone() { 121 void checkDone() {
122 if (ends.length < 2 * socketCount) return; 122 if (ends.length < 2 * socketCount) return;
123 for (var end in ends) { 123 for (var end in ends) {
124 end.close(); 124 end.close();
125 } 125 }
126 server.close(); 126 server.close();
127 port.close(); 127 port.close();
128 } 128 }
129 129
(...skipping 20 matching lines...) Expand all
150 useBuiltinRoots: false); 150 useBuiltinRoots: false);
151 151
152 testCloseOneEnd("client"); 152 testCloseOneEnd("client");
153 testCloseOneEnd("server"); 153 testCloseOneEnd("server");
154 testCloseBothEnds(); 154 testCloseBothEnds();
155 testCloseServer(); 155 testCloseServer();
156 testPauseServerSocket(); 156 testPauseServerSocket();
157 // TODO(whesse): Add testPauseSocket from raw_socket_test.dart. 157 // TODO(whesse): Add testPauseSocket from raw_socket_test.dart.
158 // TODO(whesse): Add testCancelResubscribeSocket from raw_socket_test.dart. 158 // TODO(whesse): Add testCancelResubscribeSocket from raw_socket_test.dart.
159 } 159 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_shutdown_test.dart ('k') | tests/standalone/io/raw_secure_server_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698