Skip to content

Commit 0b2ced7

Browse files
committed
Self-review
1 parent b5b8ed2 commit 0b2ced7

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

distributed/deploy/tests/test_local.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -979,26 +979,29 @@ async def test_scale_memory_cores():
979979
assert len(cluster.worker_spec) == 4
980980

981981

982-
@gen_test()
983-
async def test_repr():
982+
@pytest.mark.asyncio
983+
@pytest.mark.parametrize("memory_limit", ["2 GiB", None])
984+
async def test_repr(memory_limit, cleanup):
984985
async with LocalCluster(
985986
n_workers=2,
986987
processes=False,
987988
threads_per_worker=2,
988-
memory_limit="2 GiB",
989+
memory_limit=memory_limit,
989990
asynchronous=True,
990991
dashboard_address=":0",
991992
) as cluster:
992-
async with Client(cluster, asynchronous=True) as client:
993-
await client.wait_for_workers(2)
993+
# __repr__ uses cluster.scheduler_info, which slightly lags behind
994+
# cluster.scheduler.workers and client.wait_for_workers.
995+
while len(cluster.scheduler_info["workers"]) < 2:
996+
await asyncio.sleep(0.01)
997+
994998
text = repr(cluster)
995999
assert cluster.scheduler_address in text
996-
assert "workers=2, threads=4, memory=4.00 GiB" in text
997-
998-
async with LocalCluster(
999-
n_workers=2, processes=False, memory_limit=None, asynchronous=True
1000-
) as cluster:
1001-
assert "memory" not in repr(cluster)
1000+
assert "workers=2, threads=4" in text
1001+
if memory_limit:
1002+
assert "memory=4.00 GiB" in text
1003+
else:
1004+
assert "memory" not in text
10021005

10031006

10041007
@gen_test()

distributed/deploy/tests/test_spec_cluster.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def _():
3434
1: {"cls": Worker, "options": {"nthreads": 2}},
3535
"my-worker": {"cls": MyWorker, "options": {"nthreads": 3}},
3636
}
37-
scheduler = {"cls": Scheduler, "options": {"port": 0}}
37+
scheduler = {"cls": Scheduler, "options": {"port": 0, "dashboard_address": ":0"}}
3838

3939

4040
@gen_test()
@@ -89,9 +89,7 @@ def test_spec_sync(loop):
8989

9090

9191
def test_loop_started():
92-
with SpecCluster(
93-
worker_spec, scheduler={"cls": Scheduler, "options": {"port": 0}}
94-
) as cluster:
92+
with SpecCluster(worker_spec, scheduler=scheduler):
9593
pass
9694

9795

@@ -146,7 +144,7 @@ async def test_adaptive_killed_worker():
146144
async with SpecCluster(
147145
asynchronous=True,
148146
worker={"cls": Nanny, "options": {"nthreads": 1}},
149-
scheduler={"cls": Scheduler, "options": {"port": 0}},
147+
scheduler=scheduler,
150148
) as cluster:
151149
async with Client(cluster, asynchronous=True) as client:
152150
# Scale up a cluster with 1 worker.
@@ -221,7 +219,7 @@ async def test_broken_worker():
221219
async with SpecCluster(
222220
asynchronous=True,
223221
workers={"good": {"cls": Worker}, "bad": {"cls": BrokenWorker}},
224-
scheduler={"cls": Scheduler, "options": {"port": 0}},
222+
scheduler=scheduler,
225223
):
226224
pass
227225

@@ -254,12 +252,8 @@ def new_worker_spec(self):
254252

255253
@gen_test()
256254
async def test_nanny_port():
257-
scheduler = {"cls": Scheduler}
258255
workers = {0: {"cls": Nanny, "options": {"port": 9200}}}
259-
260-
async with SpecCluster(
261-
scheduler=scheduler, workers=workers, asynchronous=True
262-
) as cluster:
256+
async with SpecCluster(scheduler=scheduler, workers=workers, asynchronous=True):
263257
pass
264258

265259

0 commit comments

Comments
 (0)