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

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

Issue 24539002: dart:io | Enable connection cache for secure networking clients. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
« no previous file with comments | « runtime/bin/secure_socket.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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=
Søren Thygesen Gjesse 2013/09/25 10:34:59 Maybe remove these so that this test with delays i
Bill Hesse 2013/09/25 11:19:54 Left only --short-write and none.
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 // Tests multiple secure connections from a client to a server.
10 // A delay is inserted so that later connections use the secure
11 // connection cache to reestablish connection with a shorter handshake.
Søren Thygesen Gjesse 2013/09/25 10:34:59 I guess that there is not way to check if this is
Bill Hesse 2013/09/25 11:19:54 No.
12
9 13
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"; 16 import "dart:async";
13 import "dart:io"; 17 import "dart:io";
14 import "dart:isolate"; 18 import "dart:isolate";
15 19
16 const HOST_NAME = "localhost"; 20 const HOST_NAME = "localhost";
17 const CERTIFICATE = "localhost_cert"; 21 const CERTIFICATE = "localhost_cert";
18 Future<SecureServerSocket> startServer() { 22 Future<SecureServerSocket> startServer() {
19 return SecureServerSocket.bind(HOST_NAME, 23 return SecureServerSocket.bind(HOST_NAME,
20 0, 24 0,
21 CERTIFICATE).then((server) { 25 CERTIFICATE).then((server) {
22 server.listen((SecureSocket client) { 26 server.listen((SecureSocket client) {
23 client.fold(<int>[], (message, data) => message..addAll(data)) 27 client.fold(<int>[], (message, data) => message..addAll(data))
24 .then((message) { 28 .then((message) {
25 String received = new String.fromCharCodes(message); 29 String received = new String.fromCharCodes(message);
26 Expect.isTrue(received.contains("Hello from client ")); 30 Expect.isTrue(received.contains("Hello from client "));
27 String name = received.substring(received.indexOf("client ") + 7); 31 String name = received.substring(received.indexOf("client ") + 7);
28 client.add("Welcome, client $name".codeUnits); 32 client.add("Welcome, client $name".codeUnits);
29 client.close(); 33 client.close();
30 }); 34 });
31 }); 35 });
32 return server; 36 return server;
33 }); 37 });
34 } 38 }
35 39
40 Duration delay = new Duration(milliseconds: 0);
41 Duration betweenTests = new Duration(milliseconds: 200);
Søren Thygesen Gjesse 2013/09/25 10:34:59 Move or duplicate the comment here.
Bill Hesse 2013/09/25 11:19:54 Done.
36 Future testClient(server, name) { 42 Future testClient(server, name) {
37 return SecureSocket.connect(HOST_NAME, server.port).then((socket) { 43 delay += betweenTests;
44 return new Future.delayed(delay).then((_) {
45 return SecureSocket.connect(HOST_NAME, server.port);
46 }).then((socket) {
38 socket.add("Hello from client $name".codeUnits); 47 socket.add("Hello from client $name".codeUnits);
39 socket.close(); 48 socket.close();
40 return socket.fold(<int>[], (message, data) => message..addAll(data)) 49 return socket.fold(<int>[], (message, data) => message..addAll(data))
41 .then((message) { 50 .then((message) {
42 Expect.listEquals("Welcome, client $name".codeUnits, message); 51 Expect.listEquals("Welcome, client $name".codeUnits, message);
43 return server; 52 return server;
44 }); 53 });
45 }); 54 });
46 } 55 }
47 56
48 void main() { 57 void main() {
49 var certificateDatabase = join(dirname(Platform.script), 'pkcert'); 58 var certificateDatabase = join(dirname(Platform.script), 'pkcert');
50 SecureSocket.initialize(database: certificateDatabase, 59 SecureSocket.initialize(database: certificateDatabase,
51 password: 'dartdart'); 60 password: 'dartdart');
52 61
53 startServer() 62 startServer()
54 .then((server) => Future.wait( 63 .then((server) => Future.wait(
55 ['able', 'baker', 'charlie', 'dozen', 'elapse'] 64 ['able', 'baker', 'charlie', 'dozen', 'elapse']
56 .map((name) => testClient(server, name)))) 65 .map((name) => testClient(server, name))))
57 .then((servers) => servers.first.close()); 66 .then((servers) => servers.first.close());
58 } 67 }
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698