Ejemplo n.º 1
0
def test_python_version():

    server_handle, _ = ray_client_server.init_and_serve("localhost:50051")
    try:
        ray = RayAPIStub()
        info1 = ray.connect("localhost:50051")
        assert info1["python_version"] == ".".join(
            [str(x) for x in list(sys.version_info)[:3]])
        ray.disconnect()
        time.sleep(1)

        def mock_connection_response():
            return ray_client_pb2.ConnectionInfoResponse(
                num_clients=1,
                python_version="2.7.12",
                ray_version="",
                ray_commit="",
            )

        # inject mock connection function
        server_handle.data_servicer._build_connection_response = \
            mock_connection_response

        ray = RayAPIStub()
        with pytest.raises(RuntimeError):
            _ = ray.connect("localhost:50051")

        ray = RayAPIStub()
        info3 = ray.connect("localhost:50051", ignore_version=True)
        assert info3["num_clients"] == 1, info3
        ray.disconnect()
    finally:
        ray_client_server.shutdown_with_server(server_handle.grpc_server)
        time.sleep(2)
Ejemplo n.º 2
0
def test_num_clients():
    # Tests num clients reporting; useful if you want to build an app that
    # load balances clients between Ray client servers.
    server_handle, _ = ray_client_server.init_and_serve("localhost:50051")
    server = server_handle.grpc_server
    try:
        api1 = RayAPIStub()
        info1 = api1.connect("localhost:50051")
        assert info1["num_clients"] == 1, info1
        api2 = RayAPIStub()
        info2 = api2.connect("localhost:50051")
        assert info2["num_clients"] == 2, info2

        # Disconnect the first two clients.
        api1.disconnect()
        api2.disconnect()
        time.sleep(1)

        api3 = RayAPIStub()
        info3 = api3.connect("localhost:50051")
        assert info3["num_clients"] == 1, info3

        # Check info contains ray and python version.
        assert isinstance(info3["ray_version"], str), info3
        assert isinstance(info3["ray_commit"], str), info3
        assert isinstance(info3["python_version"], str), info3
        assert isinstance(info3["protocol_version"], str), info3
        api3.disconnect()
    finally:
        ray_client_server.shutdown_with_server(server)
        time.sleep(2)
Ejemplo n.º 3
0
 def shutdown(self, _exiting_interpreter=False):
     self.disconnect()
     import ray.util.client.server.server as ray_client_server
     if self._server is None:
         return
     ray_client_server.shutdown_with_server(self._server,
                                            _exiting_interpreter)
     self._server = None
Ejemplo n.º 4
0
def init_and_serve_lazy():
    cluster = ray._private.cluster_utils.Cluster()
    cluster.add_node(num_cpus=1, num_gpus=0)
    address = cluster.address

    def connect():
        ray.init(address=address)

    server_handle = ray_client_server.serve("localhost:50051", connect)
    yield server_handle
    ray_client_server.shutdown_with_server(server_handle.grpc_server)
    time.sleep(2)
Ejemplo n.º 5
0
def init_and_serve_lazy():
    cluster = ray.cluster_utils.Cluster()
    cluster.add_node(num_cpus=1, num_gpus=0)
    cluster.wait_for_nodes(1)
    address = cluster.address

    def connect(job_config=None):
        ray.init(address=address, job_config=job_config)

    server_handle = ray_client_server.serve("localhost:50051", connect)
    yield server_handle
    ray_client_server.shutdown_with_server(server_handle.grpc_server)
    time.sleep(2)
Ejemplo n.º 6
0
def test_basic_preregister():
    from ray.util.client import ray
    server, _ = ray_client_server.init_and_serve("localhost:50051")
    try:
        ray.connect("localhost:50051")
        val = ray.get(hello_world.remote())
        print(val)
        assert val >= 20
        assert val <= 200
        c = C.remote(3)
        x = c.double.remote()
        y = c.double.remote()
        ray.wait([x, y])
        val = ray.get(c.get.remote())
        assert val == 12
    finally:
        ray.disconnect()
        ray_client_server.shutdown_with_server(server)
        time.sleep(2)
Ejemplo n.º 7
0
def init_and_serve():
    server_handle, _ = ray_client_server.init_and_serve("localhost:50051")
    yield server_handle
    ray_client_server.shutdown_with_server(server_handle.grpc_server)
    time.sleep(2)