Skip to content

Commit

Permalink
Add test for listen_elastic_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
frostyplanet committed Jul 14, 2024
1 parent 127fab2 commit 2b36b05
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions python/xoscar/backends/indigen/tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,46 @@ async def test_create_actor_pool():
assert len(global_router._mapping) == 0


@pytest.mark.asyncio
async def test_create_actor_pool_elastic_ip():
start_method = (
os.environ.get("POOL_START_METHOD", "forkserver")
if sys.platform != "win32"
else None
)
pool = await create_actor_pool(
"111.111.111.111",
pool_cls=MainActorPool,
n_process=0,
subprocess_start_method=start_method,
extra_conf={"listen_elastic_ip": True},
)
async with pool:
# test global router
global_router = Router.get_instance()
# global router should not be the identical one with pool's router
assert global_router is not pool.router
assert pool.external_address in global_router._curr_external_addresses
assert pool.external_address in global_router._mapping
assert pool.external_address == "111.111.111.111"

ctx = get_context()

# actor on main pool
actor_ref = await ctx.create_actor(
TestActor, uid="test-1", address=pool.external_address
)
assert await actor_ref.add(3) == 3
await ctx.destroy_actor(actor_ref)
assert (await ctx.has_actor(actor_ref)) is False

assert pool.stopped
# after pool shutdown, global router must has been cleaned
global_router = Router.get_instance()
assert len(global_router._curr_external_addresses) == 0
assert len(global_router._mapping) == 0


@pytest.mark.asyncio
async def test_errors():
with pytest.raises(ValueError):
Expand Down

0 comments on commit 2b36b05

Please sign in to comment.