Commit cd39b0b0 authored by Tomas Krizek's avatar Tomas Krizek Committed by Petr Špaček

pytests/conn_flood: select number of connections dynamically

parent f770e601
......@@ -17,7 +17,7 @@ from kresd import Kresd
import utils
MAX_SOCKETS = 15000 # upper bound of how many connections to open
MAX_SOCKETS = 20000 # upper bound of how many connections to open
MAX_ITERATIONS = 20 # number of iterations to run the test
# we can't use softlimit ifself since kresd already has open sockets,
......@@ -34,20 +34,26 @@ RESERVED_NOFILE = 40 # 40 is empirical value
def test_conn_flood(tmpdir, sock_func_name):
def create_sockets(make_sock, nsockets):
sockets = []
next_ping = time.time() + 5 # less than tcp idle timeout
next_ping = time.time() + 4 # less than tcp idle timeout / 2
while True:
additional_sockets = 0
while time.time() < next_ping:
nsock_to_init = min(100, nsockets - len(sockets))
if not nsock_to_init:
return sockets
sockets.extend([make_sock() for _ in range(nsock_to_init)])
additional_sockets += nsock_to_init
# large number of connections can take a lot of time to open
# send some valid data to avoid TCP idle timeout for already open sockets
next_ping = time.time() + 5
next_ping = time.time() + 4
for s in sockets:
utils.ping_alive(s)
# break when no more than 10% additional sockets are created
if additional_sockets / len(sockets) < 0.1:
return sockets
max_num_of_open_files = resource.getrlimit(resource.RLIMIT_NOFILE)[0] - RESERVED_NOFILE
nsockets = min(max_num_of_open_files, MAX_SOCKETS)
......@@ -55,9 +61,9 @@ def test_conn_flood(tmpdir, sock_func_name):
ip = '127.0.0.1'
ip6 = '::1'
with Kresd(tmpdir, ip=ip, ip6=ip6, verbose=False) as kresd:
print("\nEstablishing {} connections".format(nsockets))
make_sock = getattr(kresd, sock_func_name) # function for creating sockets
sockets = create_sockets(make_sock, nsockets)
print("\nEstablished {} connections".format(len(sockets)))
print("Start sending data")
for i in range(MAX_ITERATIONS):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment