|
21 | 21 | import zipfile |
22 | 22 | from collections import deque |
23 | 23 | from collections.abc import Generator |
24 | | -from contextlib import contextmanager, nullcontext |
| 24 | +from contextlib import ExitStack, contextmanager, nullcontext |
25 | 25 | from functools import partial |
26 | 26 | from operator import add |
27 | 27 | from threading import Semaphore |
|
71 | 71 | from distributed.cluster_dump import load_cluster_dump |
72 | 72 | from distributed.comm import CommClosedError |
73 | 73 | from distributed.compatibility import LINUX, WINDOWS |
74 | | -from distributed.core import Server, Status |
| 74 | +from distributed.core import Status |
75 | 75 | from distributed.metrics import time |
76 | 76 | from distributed.scheduler import CollectTaskMetaDataPlugin, KilledWorker, Scheduler |
77 | 77 | from distributed.sizeof import sizeof |
@@ -3592,65 +3592,53 @@ async def test_scatter_raises_if_no_workers(c, s): |
3592 | 3592 | async def test_reconnect(): |
3593 | 3593 | port = open_port() |
3594 | 3594 |
|
3595 | | - async def hard_stop(s): |
3596 | | - for pc in s.periodic_callbacks.values(): |
3597 | | - pc.stop() |
| 3595 | + stack = ExitStack() |
| 3596 | + proc = popen(["dask-scheduler", "--no-dashboard", f"--port={port}"]) |
| 3597 | + stack.enter_context(proc) |
| 3598 | + async with Client(f"127.0.0.1:{port}", asynchronous=True) as c, Worker( |
| 3599 | + f"127.0.0.1:{port}" |
| 3600 | + ) as w: |
| 3601 | + await c.wait_for_workers(1, timeout=10) |
| 3602 | + x = c.submit(inc, 1) |
| 3603 | + assert (await x) == 2 |
| 3604 | + stack.close() |
3598 | 3605 |
|
3599 | | - s.stop_services() |
3600 | | - for comm in list(s.stream_comms.values()): |
3601 | | - comm.abort() |
3602 | | - for comm in list(s.client_comms.values()): |
3603 | | - comm.abort() |
| 3606 | + start = time() |
| 3607 | + while c.status != "connecting": |
| 3608 | + assert time() < start + 10 |
| 3609 | + await asyncio.sleep(0.01) |
3604 | 3610 |
|
3605 | | - await s.rpc.close() |
3606 | | - s.stop() |
3607 | | - await Server.close(s) |
| 3611 | + assert x.status == "cancelled" |
| 3612 | + with pytest.raises(CancelledError): |
| 3613 | + await x |
3608 | 3614 |
|
3609 | | - async with Scheduler(port=port) as s: |
3610 | | - async with Client(f"127.0.0.1:{port}", asynchronous=True) as c: |
3611 | | - async with Worker(f"127.0.0.1:{port}") as w: |
3612 | | - await c.wait_for_workers(1, timeout=10) |
3613 | | - x = c.submit(inc, 1) |
3614 | | - assert (await x) == 2 |
3615 | | - await hard_stop(s) |
| 3615 | + with popen(["dask-scheduler", "--no-dashboard", f"--port={port}"]): |
| 3616 | + start = time() |
| 3617 | + while c.status != "running": |
| 3618 | + await asyncio.sleep(0.1) |
| 3619 | + assert time() < start + 10 |
3616 | 3620 |
|
| 3621 | + await w.finished() |
| 3622 | + async with Worker(f"127.0.0.1:{port}"): |
3617 | 3623 | start = time() |
3618 | | - while c.status != "connecting": |
| 3624 | + while len(await c.nthreads()) != 1: |
| 3625 | + await asyncio.sleep(0.05) |
3619 | 3626 | assert time() < start + 10 |
3620 | | - await asyncio.sleep(0.01) |
3621 | | - |
3622 | | - assert x.status == "cancelled" |
3623 | | - with pytest.raises(CancelledError): |
3624 | | - await x |
3625 | 3627 |
|
3626 | | - async with Scheduler(port=port) as s2: |
3627 | | - start = time() |
3628 | | - while c.status != "running": |
3629 | | - await asyncio.sleep(0.1) |
3630 | | - assert time() < start + 10 |
3631 | | - |
3632 | | - await w.finished() |
3633 | | - async with Worker(f"127.0.0.1:{port}"): |
3634 | | - start = time() |
3635 | | - while len(await c.nthreads()) != 1: |
3636 | | - await asyncio.sleep(0.05) |
3637 | | - assert time() < start + 10 |
3638 | | - |
3639 | | - x = c.submit(inc, 1) |
3640 | | - assert (await x) == 2 |
3641 | | - await hard_stop(s2) |
| 3628 | + x = c.submit(inc, 1) |
| 3629 | + assert (await x) == 2 |
3642 | 3630 |
|
3643 | | - start = time() |
3644 | | - while True: |
3645 | | - assert time() < start + 10 |
3646 | | - try: |
3647 | | - await x |
3648 | | - assert False |
3649 | | - except CommClosedError: |
3650 | | - continue |
3651 | | - except CancelledError: |
3652 | | - break |
3653 | | - await c._close(fast=True) |
| 3631 | + start = time() |
| 3632 | + while True: |
| 3633 | + assert time() < start + 10 |
| 3634 | + try: |
| 3635 | + await x |
| 3636 | + assert False |
| 3637 | + except CommClosedError: |
| 3638 | + continue |
| 3639 | + except CancelledError: |
| 3640 | + break |
| 3641 | + await c._close(fast=True) |
3654 | 3642 |
|
3655 | 3643 |
|
3656 | 3644 | class UnhandledExceptions(Exception): |
|
0 commit comments