Skip to content

Commit c847a7b

Browse files
brianquinlanCommit Queue
authored andcommitted
test: Fix many_pending_secure_sockets_test timeouts.
Bug:#62064 Change-Id: Ie3aafd9549d7c26494faa7dddba85025e4b2cb69 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465462 Commit-Queue: Brian Quinlan <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 7ac6ad6 commit c847a7b

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed
Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,87 @@
11
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// VMOptions=
6+
// VMOptions=--short_socket_read
7+
// VMOptions=--short_socket_write
8+
// VMOptions=--short_socket_read --short_socket_write
9+
// OtherResources=certificates/server_chain.pem
10+
// OtherResources=certificates/server_key.pem
11+
// OtherResources=certificates/trusted_certs.pem
412

5-
// https://github.com/flutter/flutter/issues/170723
13+
// Verifies that a large number of secure sockets can be connected
14+
// simultaneously.
15+
//
16+
// See https://github.com/flutter/flutter/issues/170723
617

18+
import 'dart:async';
719
import "dart:io";
820

9-
test(int i) async {
10-
try {
11-
var socket = await RawSecureSocket.connect("www.google.com", 443);
12-
await Future.delayed(
13-
Duration(seconds: 6), // More than the thread pool timeout.
14-
);
15-
socket.close();
16-
} catch (e, st) {
17-
// Ignore failures from the remote side rejecting/closing the connection.
18-
if (!e.toString().contains("Connection reset by peer")) {
19-
rethrow;
20-
}
21-
}
21+
// Should be more than the number of threads that the OS can easily create.
22+
const numConnections = 2000;
23+
24+
String localFile(path) => Platform.script.resolve(path).toFilePath();
25+
26+
SecurityContext serverContext = new SecurityContext()
27+
..useCertificateChain(localFile('certificates/server_chain.pem'))
28+
..usePrivateKey(
29+
localFile('certificates/server_key.pem'),
30+
password: 'dartdart',
31+
);
32+
SecurityContext clientContext = new SecurityContext()
33+
..setTrustedCertificates(localFile('certificates/trusted_certs.pem'));
34+
35+
Future<SecureServerSocket> startServer() async {
36+
final server = await SecureServerSocket.bind(
37+
InternetAddress.loopbackIPv4,
38+
0,
39+
serverContext,
40+
);
41+
server.listen((SecureSocket client) async {
42+
client.write('Connected!');
43+
await client.flush();
44+
client.listen((_) {}, onDone: () => client.close());
45+
});
46+
return server;
47+
}
48+
49+
Future<RawSecureSocket> connectSocket(int port) async {
50+
final socket = await RawSecureSocket.connect(
51+
InternetAddress.loopbackIPv4,
52+
port,
53+
context: clientContext,
54+
);
55+
await socket.firstWhere((e) => e == RawSocketEvent.read);
56+
return socket;
2257
}
2358

2459
main() async {
25-
var tests = <Future>[];
26-
for (var i = 0; i < 2000; i++) {
27-
tests.add(test(i));
60+
final server = await startServer();
61+
final tests = <Future>[];
62+
final allConnected = Completer<void>();
63+
64+
for (var i = 0; i < numConnections;) {
65+
// Performing thousands of simultaneous TLS connections can result in
66+
// timeouts. So connect 20 sockets at a time.
67+
final socketConnections = <Future<RawSecureSocket>>[];
68+
for (var j = 0; i < numConnections && j < 20; i++, j++) {
69+
socketConnections.add(connectSocket(server.port));
70+
}
71+
72+
for (var socket in await Future.wait(socketConnections)) {
73+
Future<void> delayAndClose() async {
74+
await allConnected.future;
75+
await Future.delayed(
76+
Duration(seconds: 6), // More than the thread pool timeout.
77+
);
78+
socket.close();
79+
}
80+
81+
tests.add(delayAndClose());
82+
}
2883
}
84+
allConnected.complete();
2985
await Future.wait(tests);
86+
server.close();
3087
}

tests/standalone/standalone.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
io/http_close_stack_overflow_test: Skip # The test is heavy loaded. Should be used for manual test.
99
io/http_linklocal_ipv6_test: SkipByDesign # This needs manual test.
1010
io/large_file_read_small_file_test: Slow, Pass # Test reads small file 1M times
11+
io/many_pending_secure_sockets_test: Slow, Pass # Creates many TLS connections.
1112
io/non_utf8_directory_test: Skip # Issue 33519. Temp files causing bots to go purple.
1213
io/non_utf8_file_test: Skip # Issue 33519. Temp files causing bots to go purple.
1314
io/non_utf8_link_test: Skip # Issue 33519. Temp files causing bots to go purple.

0 commit comments

Comments
 (0)