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

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

Issue 24536005: Recommit "Change two secure networking tests". Add suppression to status file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change flaky bad_certificate_test to Pass, Timeout. 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
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_write 7 // VMOptions=--short_socket_write
7 // Tests multiple secure connections from a client to a server, hitting 8 // VMOptions=--short_socket_read --short_socket_write
8 // the secure connection cache.
9 9
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 import "package:path/path.dart"; 11 import "package:path/path.dart";
12 import "dart:async"; 12 import "dart:async";
13 import "dart:io"; 13 import "dart:io";
14 import "dart:isolate"; 14 import "dart:isolate";
15 15
16 const HOST_NAME = "localhost"; 16 const HOST_NAME = "localhost";
17 const CERTIFICATE = "localhost_cert"; 17 const CERTIFICATE = "localhost_cert";
18 Future<SecureServerSocket> startServer() { 18 Future<SecureServerSocket> startServer() {
19 return SecureServerSocket.bind(HOST_NAME, 19 return SecureServerSocket.bind(HOST_NAME,
20 0, 20 0,
21 CERTIFICATE).then((server) { 21 CERTIFICATE).then((server) {
22 server.listen((SecureSocket client) { 22 server.listen((SecureSocket client) {
23 client.fold(<int>[], (message, data) => message..addAll(data)) 23 client.fold(<int>[], (message, data) => message..addAll(data))
24 .then((message) { 24 .then((message) {
25 String received = new String.fromCharCodes(message); 25 String received = new String.fromCharCodes(message);
26 Expect.isTrue(received.contains("Hello from client ")); 26 Expect.isTrue(received.contains("Hello from client "));
27 String name = received.substring(received.indexOf("client ") + 7); 27 String name = received.substring(received.indexOf("client ") + 7);
28 client.add("Welcome, client $name".codeUnits); 28 client.add("Welcome, client $name".codeUnits);
29 client.close(); 29 client.close();
30 }); 30 });
31 }); 31 });
32 return server; 32 return server;
33 }); 33 });
34 } 34 }
35 35
36 // A delay is inserted so that later connections use the secure
37 // connection cache to reestablish connection with a shorter handshake.
38 Duration delay = new Duration(milliseconds: 0);
39 Duration betweenTests = new Duration(milliseconds: 200);
40 Future testClient(server, name) { 36 Future testClient(server, name) {
41 delay += betweenTests; 37 return SecureSocket.connect(HOST_NAME, server.port).then((socket) {
42 return new Future.delayed(delay).then((_) {
43 return SecureSocket.connect(HOST_NAME, server.port);
44 }).then((socket) {
45 socket.add("Hello from client $name".codeUnits); 38 socket.add("Hello from client $name".codeUnits);
46 socket.close(); 39 socket.close();
47 return socket.fold(<int>[], (message, data) => message..addAll(data)) 40 return socket.fold(<int>[], (message, data) => message..addAll(data))
48 .then((message) { 41 .then((message) {
49 Expect.listEquals("Welcome, client $name".codeUnits, message); 42 Expect.listEquals("Welcome, client $name".codeUnits, message);
50 return server; 43 return server;
51 }); 44 });
52 }); 45 });
53 } 46 }
54 47
55 void main() { 48 void main() {
56 var certificateDatabase = join(dirname(Platform.script), 'pkcert'); 49 var certificateDatabase = join(dirname(Platform.script), 'pkcert');
57 SecureSocket.initialize(database: certificateDatabase, 50 SecureSocket.initialize(database: certificateDatabase,
58 password: 'dartdart'); 51 password: 'dartdart');
59 52
60 startServer() 53 startServer()
61 .then((server) => Future.wait( 54 .then((server) => Future.wait(
62 ['able', 'baker', 'charlie', 'dozen', 'elapse'] 55 ['able', 'baker', 'charlie', 'dozen', 'elapse']
63 .map((name) => testClient(server, name)))) 56 .map((name) => testClient(server, name))))
64 .then((servers) => servers.first.close()); 57 .then((servers) => servers.first.close());
65 } 58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698