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

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

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