def test_push(init): @ray.remote class MyActor: def __init__(self): pass def f(self, x): return x + 1 def double(self, x): return 2 * x a1, a2, a3 = MyActor.remote(), MyActor.remote(), MyActor.remote() pool = ActorPool([a1]) pool.submit(lambda a, v: a.double.remote(v), 1) assert pool.has_free() is False # actor is busy with pytest.raises(ValueError): pool.push(a1) pool.push(a2) assert pool.has_free() # a2 is available pool.submit(lambda a, v: a.double.remote(v), 1) pool.submit(lambda a, v: a.double.remote(v), 1) assert pool.has_free() is False assert len(pool._pending_submits) == 1 pool.push(a3) assert pool.has_free() is False # a3 is used for pending submit assert len(pool._pending_submits) == 0
def test_pop_idle(init): @ray.remote class MyActor: def __init__(self): pass def f(self, x): return x + 1 def double(self, x): return 2 * x actors = [MyActor.remote()] pool = ActorPool(actors) pool.submit(lambda a, v: a.double.remote(v), 1) assert pool.pop_idle() is None assert pool.has_free() is False # actor is busy assert pool.get_next() == 2 assert pool.has_free() pool.pop_idle() # removes actor from pool assert pool.has_free() is False # no more actors in pool