]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests/conn_flood: select number of connections dynamically
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 11 Dec 2018 17:19:15 +0000 (18:19 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 13 Dec 2018 11:29:14 +0000 (11:29 +0000)
tests/pytests/conn_flood.py

index 5b7a76d2dc574bcff3dd90f701ff671e1ece400e..aa53b7007b0436179f6f7ef58e1fd660dcbb171f 100644 (file)
@@ -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):