Skip to content

Commit

Permalink
Fix if-else for send_recv_from_rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Aug 1, 2024
1 parent 564f28b commit 5c91eb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions distributed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,11 @@ async def send_recv_from_rpc(**kwargs):
except (RPCClosed, CommClosedError) as e:
if comm:
raise type(e)(
f"Exception while trying to call remote method {key!r} before comm was established."
f"Exception while trying to call remote method {key!r} using comm {comm!r}."
) from e
else:
raise type(e)(
f"Exception while trying to call remote method {key!r} using comm {comm!r}."
f"Exception while trying to call remote method {key!r} before comm was established."
) from e

self.comms[comm] = True # mark as open
Expand Down
15 changes: 15 additions & 0 deletions distributed/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from distributed.comm.tcp import TCPBackend, TCPListener
from distributed.core import (
ConnectionPool,
RPCClosed,
Server,
Status,
_expects_comm,
Expand Down Expand Up @@ -923,6 +924,20 @@ async def test_rpc_serialization():
assert result == {"result": inc}


@gen_test()
async def test_rpc_closed_exception():
async with Server({"echo": echo_serialize}) as server:
await server.listen("tcp://")

async with rpc(server.address, serializers=["msgpack"]) as r:
r.status = Status.closed
with pytest.raises(
RPCClosed,
match="Exception while trying to call remote method .* before comm was established.",
):
await r.__getattr__("foo")()


@gen_cluster()
async def test_thread_id(s, a, b):
assert s.thread_id == a.thread_id == b.thread_id == threading.get_ident()
Expand Down

0 comments on commit 5c91eb9

Please sign in to comment.