def test_service_group_start(): test_service_1 = HttpService(SERVICE_COMMAND) test_service_2 = HttpService(SERVICE_COMMAND) with ServiceGroup(test_service_1, test_service_2): assert requests.get(test_service_1.url).status_code == 200 assert requests.get(test_service_2.url).status_code == 200
def test_timeout_error_on_too_long_service_stop(): unstoppable_service_path = os.path.join(os.path.dirname(__file__), 'unstoppable_service.py') service = HttpService([sys.executable, unstoppable_service_path, '{port}']) service.start() try: with pytest.raises(subprocess.TimeoutExpired): service.stop(0.001) finally: # cleanup by ending the service process service._service_proc.terminate()
def test_service_start_timeout_and_cleanup(): never_starting_service = os.path.join(os.path.dirname(__file__), 'never_starting_service.py') test_service = HttpService([sys.executable, never_starting_service, '{port}']) with pytest.raises(TimeoutError): # If this timeout is lower, then the test can sometimes fail. # It looks like Python can ignore SIGINT in the early process startup, # but this needs to be verified. # This wouldn't be a problem with SIGTERM. test_service.start(timeout=0.1) test_service._service_proc.wait(timeout=1.0)
def test_service_start_timeout_and_cleanup(): never_starting_service = os.path.join(os.path.dirname(__file__), 'never_starting_service.py') test_service = HttpService( [sys.executable, never_starting_service, '{port}']) with pytest.raises(TimeoutError): # If this timeout is lower, then the test can sometimes fail. # It looks like Python can ignore SIGINT in the early process startup, # but this needs to be verified. # This wouldn't be a problem with SIGTERM. test_service.start(timeout=0.1) test_service._service_proc.wait(timeout=1.0)
def test_service_start_and_cleanup(): service_port = port_for.select_random() with HttpService(SERVICE_COMMAND, service_port) as service: assert requests.get(service.url).status_code == 200 with pytest.raises(requests.exceptions.ConnectionError): requests.get(service.url)
def das_session(vcap_services, uaa_imposter): waitress_path = os.path.join(os.path.dirname(sys.executable), 'waitress-serve') das_command = [ waitress_path, '--port', '{port}', '--call', 'data_acquisition.app:get_app'] project_root_path = os.path.join(waitress_path, '../../../..') das_service = HttpService( das_command, env={ 'VCAP_APPLICATION': TEST_VCAP_APPLICATION, 'VCAP_SERVICES': vcap_services, 'VCAP_APP_PORT': '{port}', 'PYTHONPATH': project_root_path}) das_service.start() yield das_service das_service.stop()
def test_service_env_config(): example_service_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'example_service.py' ) service_port = port_for.select_random() service = HttpService( [sys.executable, example_service_path], port=service_port, env={'TEST_APP_PORT': '{port}'}) with service: assert requests.get(service.base_url).text == 'Just some text.'
def das_session(vcap_services, uaa_imposter): waitress_path = os.path.join(os.path.dirname(sys.executable), 'waitress-serve') das_command = [ waitress_path, '--port', '{port}', '--call', 'data_acquisition.app:get_app' ] project_root_path = os.path.join(waitress_path, '../../../..') das_service = HttpService(das_command, env={ 'VCAP_APPLICATION': TEST_VCAP_APPLICATION, 'VCAP_SERVICES': vcap_services, 'VCAP_APP_PORT': '{port}', 'PYTHONPATH': project_root_path }) das_service.start() yield das_service das_service.stop()
def test_service_env_without_parent(): service_env = {'bla': 'aaa'} service = HttpService('some fake command', env=service_env, copy_parent_env=False) assert service._service_env == service_env
def test_service_env_from_parent(service_env, parent_env, final_env): os.environ = parent_env service = HttpService('some fake command', env=service_env) assert service._service_env == final_env
def test_service_configuration_through_env_vars(): service = HttpService(SERVICE_COMMAND[:-1], env={'TEST_APP_PORT': '{port}'}) with service: assert requests.get(service.url).text == 'Just some text.'
def test_service_single_string_command(): single_string_command = 'mb' service = HttpService(single_string_command, 12345) assert service._process_command == single_string_command
def test_service_base_url(): service = HttpService('fake-command', 12345) assert service.url == 'http://localhost:12345'
def test_service_timeout_and_cleanup(): test_service = HttpService(TEST_SERVICE_COMMAND) with pytest.raises(TimeoutError): test_service.start(timeout=0.001) test_service._service_proc.wait(timeout=3.0)