def test_wait_for_connection_success(): success_tracker = {} port = get_open_port() def _do_client(): success_tracker['client_booted'] = True try: wait_for_connection('localhost', port) except Timeout: success_tracker['client_success'] = False else: success_tracker['client_success'] = True finally: success_tracker['client_exited'] = True class TestHTTPServer(HTTPServer): timeout = 30 def handle_timeout(self): success_tracker['server_success'] = False def handle_error(self): success_tracker['server_success'] = True def _do_server(): success_tracker['server_booted'] = True server = TestHTTPServer(('localhost', port), BaseHTTPRequestHandler) server.timeout = 30 success_tracker['server_before_handle'] = True server.handle_request() success_tracker['server_after_handle'] = True success_tracker.setdefault('server_success', True) success_tracker['server_exited'] = True client_thread = spawn(_do_client) server_thread = spawn(_do_server) try: with Timeout(5) as _timeout: while 'client_success' not in success_tracker and 'server_success' not in success_tracker: _timeout.sleep(random.random()) except Timeout: pass assert 'client_success' in success_tracker assert success_tracker['client_success'] is True assert 'server_success' in success_tracker assert success_tracker['server_success'] is True
def compile_cmd(ctx, watch): """ Compile project contracts, storing their output in `./build/contracts.json` Call bare to compile all contracts or specify contract names or file paths to restrict to only compiling those contracts. Pass in a file path and a contract name separated by a colon(":") to specify only named contracts in the specified file. """ project = ctx.obj['PROJECT'] compiler_settings = project.config.get('compilation.settings', {}) _, compiled_contract_data = compile_project_contracts( project, compiler_settings) write_compiled_sources(project.compiled_contracts_asset_path, compiled_contract_data) if watch: thread = spawn( watch_project_contracts, project=project, compiler_settings=compiler_settings, ) thread.join()
def compile_project(project, watch): _, compiled_contracts = compile_project_contracts(project) write_compiled_sources(project.compiled_contracts_asset_path, compiled_contracts) if watch: thread = spawn( watch_project_contracts, project=project, ) thread.join()
def test_wait_for_connection_failure(): success_tracker = {} port = get_open_port() def _do_client(): success_tracker['client_booted'] = True try: wait_for_connection('localhost', port, 2) except Timeout: success_tracker['client_success'] = False else: success_tracker['client_success'] = True spawn(_do_client) try: with Timeout(5) as _timeout: while 'client_success' not in success_tracker: _timeout.sleep(random.random()) except Timeout: pass assert 'client_success' in success_tracker assert success_tracker['client_success'] is False