Skip to content

Commit

Permalink
improved stress script
Browse files Browse the repository at this point in the history
  • Loading branch information
gk-fschubert committed Jan 27, 2025
1 parent 104e06b commit baad0d5
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/tests/tls/stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import ssl
import logging
from datetime import datetime

class SSLClient:
def __init__(self, ip, client_cert_file_location, trusted_cas_file_location):
Expand Down Expand Up @@ -32,26 +33,39 @@ def connect_to_server(self, ip, port, client_cert_file, ca_file_location):


def send_stuff(x):
try:
test = SSLClient('127.0.0.1', '../../../raddb/certs/client.pem', '../../../raddb/certs/ca.pem')

test.socket.send(b'asdlkfjasldkfj')
test.socket.shutdown(socket.SHUT_WR)
test.socket.recv(1024)
test.socket.close()
except Exception as e:
print('error while sending things')
finally:
while True:
try:
now = datetime.now()
test = SSLClient('127.0.0.1', '../../../raddb/certs/client.pem', '../../../raddb/certs/ca.pem')
test.socket.send(b'asdlkfjasldkfj')
test.socket.shutdown(socket.SHUT_WR)
# don't wait until a clean shutdown is done and close it directly
test.socket.close()
except:
pass

except Exception as e:
print(f'dur: {(datetime.now() - now)} _ error while sending things: {str(e)}')
finally:
try:
if not hasattr(test.socket, '_closed'):
print(f'dur: {(datetime.now() - now)} _ socket not correctly initialized')
elif not test.socket._closed:
test.socket.close()
print(f"dur: {(datetime.now() - now)}")
except Exception as e:
print(f'dur: {(datetime.now() - now)} _ error while closing socket: {str(e)}')
pass




if __name__ == '__main__':
with multiprocessing.Pool(16) as p:
with multiprocessing.Pool(16) as p:
while True:
p.map(send_stuff, range(400))
time.sleep(1)
try:
p.map(send_stuff, range(16))
except KeyboardInterrupt:
logging.info("Keyboard interrupt")
break
except Exception as e:
logging.error(f"Not able to spwan process: {e}")

0 comments on commit baad0d5

Please sign in to comment.