Skip to content

Commit

Permalink
test that client fast closes on aexit
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Aug 23, 2022
1 parent 82a724f commit d6f6561
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions distributed/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from threading import Semaphore
from time import sleep
from typing import Any
from unittest import mock

import psutil
import pytest
Expand Down Expand Up @@ -7538,3 +7539,21 @@ def __init__(self, *args, **kwargs):
(DeprecationWarning, "The io_loop property is deprecated"),
(DeprecationWarning, "setting the loop property is deprecated"),
]


@gen_cluster(client=False, nthreads=[])
async def test_fast_close_on_aexit_failure(s):
class MyException(Exception):
pass

c = Client(s.address, asynchronous=True)
with mock.patch.object(c, "_close", wraps=c._close) as _close_proxy:
with pytest.raises(MyException):
async with c:
start = time()
raise MyException
stop = time()

assert _close_proxy.mock_calls == [mock.call(fast=True)]
assert c.status == "closed"
assert (stop - start) < 2

0 comments on commit d6f6561

Please sign in to comment.