def grpc_health_check_command(port=None, socket=None, host="localhost"): if seven.IS_WINDOWS and port is None: raise click.UsageError( "You must pass a valid --port/-p on Windows: --socket/-s not supported." ) if not (port or socket and not (port and socket)): raise click.UsageError("You must pass one and only one of --port/-p or --socket/-s.") client = DagsterGrpcClient(port=port, socket=socket, host=host) status = client.health_check_query() if status != "SERVING": sys.exit(1)
def test_fixed_server_id(): port = find_free_port() server_process = open_server_process(port=port, socket=None, fixed_server_id="fixed_id") assert server_process is not None try: api_client = DagsterGrpcClient(port=port) assert api_client.get_server_id() == "fixed_id" finally: interrupt_ipc_subprocess_pid(server_process.pid)
def test_server_socket(): with safe_tempfile_path() as skt: server_process = open_server_process(port=None, socket=skt) try: assert DagsterGrpcClient(socket=skt).ping("foobar") == "foobar" finally: interrupt_ipc_subprocess_pid(server_process.pid)
def test_client_port_and_socket(): port = find_free_port() with safe_tempfile_path() as skt: with pytest.raises( check.CheckError, match=re.escape( "You must pass one and only one of `port` or `socket`."), ): DagsterGrpcClient(port=port, socket=skt)
def test_server_port(): port = find_free_port() server_process = open_server_process(port=port, socket=None) assert server_process is not None try: assert DagsterGrpcClient(port=port).ping("foobar") == "foobar" finally: if server_process is not None: interrupt_ipc_subprocess_pid(server_process.pid)
def test_detect_server_restart(): # Create first server and query ID port, server_process = create_server_process() try: api_client = DagsterGrpcClient(port=port) server_id_one = api_client.get_server_id() assert server_id_one finally: interrupt_ipc_subprocess_pid(server_process.pid) seven.wait_for_process(server_process, timeout=5) with pytest.raises(DagsterUserCodeUnreachableError): api_client.get_server_id() # Create second server and query ID port, server_process = create_server_process() try: api_client = DagsterGrpcClient(port=port) server_id_two = api_client.get_server_id() assert server_id_two finally: interrupt_ipc_subprocess_pid(server_process.pid) assert server_id_one != server_id_two
def test_detect_server_restart(): # Create first server and query ID port, server_process = create_server_process() try: api_client = DagsterGrpcClient(port=port) server_id_one = api_client.get_server_id() assert server_id_one finally: interrupt_ipc_subprocess_pid(server_process.pid) seven.wait_for_process(server_process, timeout=5) with pytest.raises(grpc._channel._InactiveRpcError): # pylint: disable=protected-access api_client.get_server_id() # Create second server and query ID port, server_process = create_server_process() try: api_client = DagsterGrpcClient(port=port) server_id_two = api_client.get_server_id() assert server_id_two finally: interrupt_ipc_subprocess_pid(server_process.pid) assert server_id_one != server_id_two
def test_client_socket_on_windows(): with safe_tempfile_path() as skt: with pytest.raises(check.CheckError, match=re.escape("`socket` not supported.")): DagsterGrpcClient(socket=skt)
def test_client_bad_socket(): with safe_tempfile_path() as bad_socket: with pytest.raises(DagsterUserCodeUnreachableError) as exc_info: DagsterGrpcClient(socket=bad_socket).ping("foobar") assert "failed to connect to all addresses" in str(exc_info.getrepr())
def test_client_bad_port(): port = find_free_port() with pytest.raises(DagsterUserCodeUnreachableError) as exc_info: DagsterGrpcClient(port=port).ping("foobar") assert "failed to connect to all addresses" in str(exc_info.getrepr())
def test_client_socket(): with safe_tempfile_path() as skt: assert DagsterGrpcClient(socket=skt)
def test_client_port_bad_host(): port = find_free_port() with pytest.raises(check.CheckError, match="Must provide a hostname"): DagsterGrpcClient(port=port, host=None)
def test_client_port(): port = find_free_port() assert DagsterGrpcClient(port=port)
def test_client_bad_socket(): with safe_tempfile_path() as bad_socket: with pytest.raises(grpc.RpcError, match='failed to connect to all addresses'): DagsterGrpcClient(socket=bad_socket).ping('foobar')
def test_client_bad_port(): port = find_free_port() with pytest.raises(grpc.RpcError, match='failed to connect to all addresses'): DagsterGrpcClient(port=port).ping('foobar')