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

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

Issue 201993002: Fix SecureSocket tests to look up localhost only once, where possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove useless change to https_client_certificate_test.dart Created 6 years, 9 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 // This test tests TLS session resume, by making multiple client connections 5 // This test tests TLS session resume, by making multiple client connections
6 // on the same port to the same server, with a delay of 200 ms between them. 6 // on the same port to the same server, with a delay of 200 ms between them.
7 // The unmodified secure_server_test creates all sessions simultaneously, 7 // The unmodified secure_server_test creates all sessions simultaneously,
8 // which means that no handshake completes and caches its keys in the session 8 // which means that no handshake completes and caches its keys in the session
9 // cache in time for other connections to use it. 9 // cache in time for other connections to use it.
10 // 10 //
11 // Session resume is currently disabled - see issue 11 // Session resume is currently disabled - see issue
12 // https://code.google.com/p/dart/issues/detail?id=7230 12 // https://code.google.com/p/dart/issues/detail?id=7230
13 // 13 //
14 // VMOptions= 14 // VMOptions=
15 // VMOptions=--short_socket_read 15 // VMOptions=--short_socket_read
16 // VMOptions=--short_socket_write 16 // VMOptions=--short_socket_write
17 // VMOptions=--short_socket_read --short_socket_write 17 // VMOptions=--short_socket_read --short_socket_write
18 18
19 import "package:expect/expect.dart";
20 import "package:path/path.dart";
21 import "dart:async"; 19 import "dart:async";
22 import "dart:io"; 20 import "dart:io";
23 import "dart:isolate"; 21 import "dart:isolate";
24 22
25 const HOST_NAME = "localhost"; 23 import "package:expect/expect.dart";
24 import "package:async_helper/async_helper.dart";
25
26 InternetAddress HOST;
26 const CERTIFICATE = "localhost_cert"; 27 const CERTIFICATE = "localhost_cert";
27 Future<SecureServerSocket> startServer() { 28 Future<SecureServerSocket> startServer() {
28 return SecureServerSocket.bind(HOST_NAME, 29 return SecureServerSocket.bind(HOST,
29 0, 30 0,
30 CERTIFICATE).then((server) { 31 CERTIFICATE).then((server) {
31 server.listen((SecureSocket client) { 32 server.listen((SecureSocket client) {
32 client.fold(<int>[], (message, data) => message..addAll(data)) 33 client.fold(<int>[], (message, data) => message..addAll(data))
33 .then((message) { 34 .then((message) {
34 String received = new String.fromCharCodes(message); 35 String received = new String.fromCharCodes(message);
35 Expect.isTrue(received.contains("Hello from client ")); 36 Expect.isTrue(received.contains("Hello from client "));
36 String name = received.substring(received.indexOf("client ") + 7); 37 String name = received.substring(received.indexOf("client ") + 7);
37 client.write("Welcome, client $name"); 38 client.write("Welcome, client $name");
38 client.close(); 39 client.close();
39 }); 40 });
40 }); 41 });
41 return server; 42 return server;
42 }); 43 });
43 } 44 }
44 45
45 Future testClient(server, name) { 46 Future testClient(server, name) {
46 return SecureSocket.connect(HOST_NAME, server.port).then((socket) { 47 return SecureSocket.connect(HOST, server.port).then((socket) {
47 socket.write("Hello from client $name"); 48 socket.write("Hello from client $name");
48 socket.close(); 49 socket.close();
49 return socket.fold(<int>[], (message, data) => message..addAll(data)) 50 return socket.fold(<int>[], (message, data) => message..addAll(data))
50 .then((message) { 51 .then((message) {
51 Expect.listEquals("Welcome, client $name".codeUnits, message); 52 Expect.listEquals("Welcome, client $name".codeUnits, message);
52 return server; 53 return server;
53 }); 54 });
54 }); 55 });
55 } 56 }
56 57
57 void main() { 58 void main() {
59 asyncStart();
58 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath(); 60 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
59 SecureSocket.initialize(database: certificateDatabase, 61 SecureSocket.initialize(database: certificateDatabase,
60 password: 'dartdart'); 62 password: 'dartdart');
63 InternetAddress.lookup("localhost").then((hosts) {
64 HOST = hosts.first;
65 runTests().then((_) => asyncEnd());
66 });
67 }
61 68
69 Future runTests() {
62 Duration delay = const Duration(milliseconds: 0); 70 Duration delay = const Duration(milliseconds: 0);
63 Duration delay_between_connections = const Duration(milliseconds: 300); 71 Duration delay_between_connections = const Duration(milliseconds: 300);
64 72 return startServer()
65 startServer()
66 .then((server) => Future.wait( 73 .then((server) => Future.wait(
67 ['able', 'baker', 'charlie', 'dozen', 'elapse'] 74 ['able', 'baker', 'charlie', 'dozen', 'elapse']
68 .map((name) { 75 .map((name) {
69 delay += delay_between_connections; 76 delay += delay_between_connections;
70 return new Future.delayed(delay, () => server) 77 return new Future.delayed(delay, () => server)
71 .then((server) => testClient(server, name)); 78 .then((server) => testClient(server, name));
72 }))) 79 })))
73 .then((servers) => servers.first.close()); 80 .then((servers) => servers.first.close());
74 } 81 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_server_socket_test.dart ('k') | tests/standalone/io/secure_socket_bad_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698