test: Fix many_pending_secure_sockets_test timeouts.

Bug:https://github.com/dart-lang/sdk/issues/62064
Change-Id: Ie3aafd9549d7c26494faa7dddba85025e4b2cb69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465462
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Brian Quinlan
2025-12-03 13:24:32 -08:00
committed by Commit Queue
parent 7ac6ad6d42
commit c847a7bf43
2 changed files with 75 additions and 17 deletions
@@ -1,30 +1,87 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// VMOptions=
// VMOptions=--short_socket_read
// VMOptions=--short_socket_write
// VMOptions=--short_socket_read --short_socket_write
// OtherResources=certificates/server_chain.pem
// OtherResources=certificates/server_key.pem
// OtherResources=certificates/trusted_certs.pem
// https://github.com/flutter/flutter/issues/170723
// Verifies that a large number of secure sockets can be connected
// simultaneously.
//
// See https://github.com/flutter/flutter/issues/170723
import 'dart:async';
import "dart:io";
test(int i) async {
try {
var socket = await RawSecureSocket.connect("www.google.com", 443);
await Future.delayed(
Duration(seconds: 6), // More than the thread pool timeout.
);
socket.close();
} catch (e, st) {
// Ignore failures from the remote side rejecting/closing the connection.
if (!e.toString().contains("Connection reset by peer")) {
rethrow;
}
}
// Should be more than the number of threads that the OS can easily create.
const numConnections = 2000;
String localFile(path) => Platform.script.resolve(path).toFilePath();
SecurityContext serverContext = new SecurityContext()
..useCertificateChain(localFile('certificates/server_chain.pem'))
..usePrivateKey(
localFile('certificates/server_key.pem'),
password: 'dartdart',
);
SecurityContext clientContext = new SecurityContext()
..setTrustedCertificates(localFile('certificates/trusted_certs.pem'));
Future<SecureServerSocket> startServer() async {
final server = await SecureServerSocket.bind(
InternetAddress.loopbackIPv4,
0,
serverContext,
);
server.listen((SecureSocket client) async {
client.write('Connected!');
await client.flush();
client.listen((_) {}, onDone: () => client.close());
});
return server;
}
Future<RawSecureSocket> connectSocket(int port) async {
final socket = await RawSecureSocket.connect(
InternetAddress.loopbackIPv4,
port,
context: clientContext,
);
await socket.firstWhere((e) => e == RawSocketEvent.read);
return socket;
}
main() async {
var tests = <Future>[];
for (var i = 0; i < 2000; i++) {
tests.add(test(i));
final server = await startServer();
final tests = <Future>[];
final allConnected = Completer<void>();
for (var i = 0; i < numConnections;) {
// Performing thousands of simultaneous TLS connections can result in
// timeouts. So connect 20 sockets at a time.
final socketConnections = <Future<RawSecureSocket>>[];
for (var j = 0; i < numConnections && j < 20; i++, j++) {
socketConnections.add(connectSocket(server.port));
}
for (var socket in await Future.wait(socketConnections)) {
Future<void> delayAndClose() async {
await allConnected.future;
await Future.delayed(
Duration(seconds: 6), // More than the thread pool timeout.
);
socket.close();
}
tests.add(delayAndClose());
}
}
allConnected.complete();
await Future.wait(tests);
server.close();
}
+1
View File
@@ -8,6 +8,7 @@
io/http_close_stack_overflow_test: Skip # The test is heavy loaded. Should be used for manual test.
io/http_linklocal_ipv6_test: SkipByDesign # This needs manual test.
io/large_file_read_small_file_test: Slow, Pass # Test reads small file 1M times
io/many_pending_secure_sockets_test: Slow, Pass # Creates many TLS connections.
io/non_utf8_directory_test: Skip # Issue 33519. Temp files causing bots to go purple.
io/non_utf8_file_test: Skip # Issue 33519. Temp files causing bots to go purple.
io/non_utf8_link_test: Skip # Issue 33519. Temp files causing bots to go purple.