Exemple #1
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)
Exemple #2
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)
Exemple #3
0
 def init(self, *args, **kwargs):
     if self._server is not None:
         raise Exception("Trying to start two instances of ray via client")
     import ray.util.client.server.server as ray_client_server
     self._server, address_info = ray_client_server.init_and_serve(
         "localhost:50051", *args, **kwargs)
     self.connect("localhost:50051")
     self._connected_with_init = True
     return address_info
Exemple #4
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)
Exemple #5
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)