Commit f3b3350e authored by Alexandre's avatar Alexandre

Refactoring

parent 15c52565
......@@ -519,27 +519,27 @@ def run_default(name, connection, opts):
request.head = opts.head
request.post = opts.post
if not opts.pipelining:
if opts.pipelining: # We do pipelining (DoT)
connection.pipelining_add_request(request)
elif opts.multistreams: # We do multistreams (DoH)
connection.multistreams_add_request(request)
else:
try:
connection.do_test(request, synchronous = not opts.multistreams)
connection.do_test(request) # perform the query
except (OpenSSL.SSL.Error, homer.ConnectionDOTException, homer.DOHException) as e:
ok = False
error(e)
break
if not opts.multistreams:
ok = request.success
print_result(connection, request)
ok = request.success
print_result(connection, request)
if opts.tests > 1 and i == 0:
start2 = time.time()
if opts.delay is not None:
time.sleep(opts.delay)
else: # We do pipelining
connection.pipelining_add_request(request)
if opts.multistreams:
connection.perform_multi(opts.show_time, display_results=opts.display_results)
if opts.dot and opts.pipelining:
elif opts.pipelining:
print()
done = 0
try:
......@@ -577,6 +577,7 @@ def run_default(name, connection, opts):
n_queries = connection.nbr_finished_queries
stop = time.time()
if n_queries > 1 and not opts.pipelining and not opts.multistreams:
extra = ", %.2f ms/request if we ignore the first one" % ((stop-start2)*1000/(n_queries-1))
else:
......@@ -585,9 +586,11 @@ def run_default(name, connection, opts):
time_tot = stop - start
time_per_request = time_tot / n_queries * 1000
print("\nTotal elapsed time: %.2f seconds (%.2f ms/request%s)" % (time_tot, time_per_request, extra))
if opts.multistreams and opts.verbose:
for rcode, n in conn.finished['http'].items():
print("HTTP %d : %d %.2f%%" % (rcode, n, n / n_queries * 100))
return ok
# Main program
......
......@@ -260,13 +260,12 @@ class ConnectionDOT(Connection):
rcode, data, size = self.receive_data(dump=dump)
request.store_response(rcode, data, size)
# this function might need to be move outside
def do_test(self, request, synchronous=True):
# this function might need to be moved outside
def do_test(self, request):
self.send_data(request.data)
if synchronous:
rcode, data, size = self.receive_data()
request.store_response(rcode, data, size)
request.check_response(self.debug)
rcode, data, size = self.receive_data()
request.store_response(rcode, data, size)
request.check_response(self.debug)
# should the pipelining methods be part of ConnectionDOT ?
def pipelining_add_request(self, request):
......@@ -278,7 +277,7 @@ class ConnectionDOT(Connection):
id = request.message.id
# TODO check there is no duplicate in IDs
self.pending[id] = (False, index, request)
self.do_test(request, synchronous = False)
self.send_data(request.data)
def pipelining_init_pending(self, max_in_flight):
for i in range(0, max_in_flight):
......@@ -403,7 +402,7 @@ class ConnectionDOH(Connection):
print("Establishing multistreams connection...")
request = homer.RequestDOH('.', qtype='NS')
request.to_wire()
self.do_test(request, synchronous=False)
self.multistreams_add_request(request)
self.perform_multi(silent=True, display_results=False, show_time=False)
self.all_handles = []
self.finished = { 'http': {} }
......@@ -501,15 +500,14 @@ class ConnectionDOH(Connection):
print(f'{handle.time * 1000:8.3f} ms', end=' ')
print(f'{(handle.time - handle.pretime) * 1000:8.3f} ms')
def do_test(self, request, synchronous=True):
if synchronous:
handle = self.curl_handle
else:
handle = create_handle(self)
self.all_handles.append(handle)
def multistreams_add_request(self, request):
handle = create_handle(self)
self.all_handles.append(handle)
handle.prepare(handle, self, request)
if synchronous:
self.send_and_receive(handle)
request.check_response(self.debug)
else:
self.multi.add_handle(handle)
self.multi.add_handle(handle)
def do_test(self, request):
handle = self.curl_handle
handle.prepare(handle, self, request)
self.send_and_receive(handle)
request.check_response(self.debug)
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