|  |  | @ -1,6 +1,4 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | import http.server |  |  |  | import http.server | 
			
		
	
		
		
			
				
					
					|  |  |  | import multiprocessing |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import queue |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import random |  |  |  | import random | 
			
		
	
		
		
			
				
					
					|  |  |  | import requests |  |  |  | import requests | 
			
		
	
		
		
			
				
					
					|  |  |  | import socket |  |  |  | import socket | 
			
		
	
	
		
		
			
				
					|  |  | @ -8,6 +6,7 @@ import time | 
			
		
	
		
		
			
				
					
					|  |  |  | from functools import wraps |  |  |  | from functools import wraps | 
			
		
	
		
		
			
				
					
					|  |  |  | from multiprocessing import Process |  |  |  | from multiprocessing import Process | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | from common.timeout import Timeout | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | class EchoSocket(): |  |  |  | class EchoSocket(): | 
			
		
	
		
		
			
				
					
					|  |  |  |   def __init__(self, port): |  |  |  |   def __init__(self, port): | 
			
		
	
	
		
		
			
				
					|  |  | @ -79,39 +78,25 @@ class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): | 
			
		
	
		
		
			
				
					
					|  |  |  |     self.end_headers() |  |  |  |     self.end_headers() | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | def http_server(port_queue, **kwargs): |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   while 1: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     try: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       port = random.randrange(40000, 50000) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       port_queue.put(port) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       http.server.test(**kwargs, port=port) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     except OSError as e: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       if e.errno == 98: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         continue |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | def with_http_server(func): |  |  |  | def with_http_server(func): | 
			
		
	
		
		
			
				
					
					|  |  |  |   @wraps(func) |  |  |  |   @wraps(func) | 
			
		
	
		
		
			
				
					
					|  |  |  |   def inner(*args, **kwargs): |  |  |  |   def inner(*args, **kwargs): | 
			
		
	
		
		
			
				
					
					|  |  |  |     port_queue = multiprocessing.Queue() |  |  |  |     with Timeout(2, 'HTTP Server did not start'): | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       p = None | 
			
		
	
		
		
			
				
					
					|  |  |  |       host = '127.0.0.1' |  |  |  |       host = '127.0.0.1' | 
			
		
	
		
		
			
				
					
					|  |  |  |     p = Process(target=http_server, |  |  |  |       while p is None or p.exitcode is not None: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 args=(port_queue,), |  |  |  |         port = random.randrange(40000, 50000) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 kwargs={ |  |  |  |         p = Process(target=http.server.test, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                   'HandlerClass': HTTPRequestHandler, |  |  |  |                     kwargs={'port': port, 'HandlerClass': HTTPRequestHandler, 'bind': host}) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                   'bind': host}) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         p.start() |  |  |  |         p.start() | 
			
		
	
		
		
			
				
					
					|  |  |  |     start = time.monotonic() |  |  |  |         time.sleep(0.1) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     port = None |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     while 1: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       if time.monotonic() - start > 10: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         raise Exception('HTTP Server did not start') |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     with Timeout(2): | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       while True: | 
			
		
	
		
		
			
				
					
					|  |  |  |         try: |  |  |  |         try: | 
			
		
	
		
		
			
				
					
					|  |  |  |         port = port_queue.get(timeout=0.1) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |           requests.put(f'http://{host}:{port}/qlog.bz2', data='') |  |  |  |           requests.put(f'http://{host}:{port}/qlog.bz2', data='') | 
			
		
	
		
		
			
				
					
					|  |  |  |           break |  |  |  |           break | 
			
		
	
		
		
			
				
					
					|  |  |  |       except (requests.exceptions.ConnectionError, queue.Empty): |  |  |  |         except requests.exceptions.ConnectionError: | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           time.sleep(0.1) |  |  |  |           time.sleep(0.1) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     try: |  |  |  |     try: | 
			
		
	
	
		
		
			
				
					|  |  | 
 |