Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async... await in tests #3706

Merged
merged 7 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dask-worker-space/
*.swp
.ycm_extra_conf.py
tags
.ipynb_checkpoints
17 changes: 5 additions & 12 deletions distributed/cli/tests/test_dask_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import tempfile
from time import sleep

from tornado import gen
from click.testing import CliRunner

import distributed
Expand All @@ -29,12 +28,9 @@
def test_defaults(loop):
with popen(["dask-scheduler", "--no-dashboard"]) as proc:

@gen.coroutine
def f():
async def f():
# Default behaviour is to listen on all addresses
yield [
assert_can_connect_from_everywhere_4_6(8786, timeout=5.0)
] # main port
await assert_can_connect_from_everywhere_4_6(8786, timeout=5.0)

with Client("127.0.0.1:%d" % Scheduler.default_port, loop=loop) as c:
c.sync(f)
Expand All @@ -49,12 +45,9 @@ def f():
def test_hostport(loop):
with popen(["dask-scheduler", "--no-dashboard", "--host", "127.0.0.1:8978"]):

@gen.coroutine
def f():
yield [
# The scheduler's main port can't be contacted from the outside
assert_can_connect_locally_4(8978, timeout=5.0)
]
async def f():
# The scheduler's main port can't be contacted from the outside
await assert_can_connect_locally_4(8978, timeout=5.0)

with Client("127.0.0.1:8978", loop=loop) as c:
assert len(c.nthreads()) == 0
Expand Down
6 changes: 2 additions & 4 deletions distributed/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from tornado import gen
from tornado.ioloop import IOLoop


Expand Down Expand Up @@ -51,11 +50,10 @@ def install_signal_handlers(loop=None, cleanup=None):
old_handlers = {}

def handle_signal(sig, frame):
@gen.coroutine
def cleanup_and_stop():
async def cleanup_and_stop():
try:
if cleanup is not None:
yield cleanup(sig)
await cleanup(sig)
finally:
loop.stop()

Expand Down
5 changes: 4 additions & 1 deletion distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def _get_global_client():
return c
else:
del _global_clients[k]
del L
return None


Expand Down Expand Up @@ -1339,6 +1338,10 @@ def close(self, timeout=no_default):
timeout = self._timeout * 2
# XXX handling of self.status here is not thread-safe
if self.status == "closed":
if self.asynchronous:
future = asyncio.Future()
future.set_result(None)
return future
return
self.status = "closing"

Expand Down
4 changes: 2 additions & 2 deletions distributed/comm/tests/test_ucx.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ async def test_ping_pong_data():


@gen_test()
def test_ucx_deserialize():
async def test_ucx_deserialize():
# Note we see this error on some systems with this test:
# `socket.gaierror: [Errno -5] No address associated with hostname`
# This may be due to a system configuration issue.
from .test_comms import check_deserialize

yield check_deserialize("tcp://")
await check_deserialize("tcp://")


@pytest.mark.asyncio
Expand Down
13 changes: 7 additions & 6 deletions distributed/dashboard/tests/test_components.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio

import pytest

pytest.importorskip("bokeh")

from bokeh.models import ColumnDataSource, Model
from tornado import gen

from distributed.utils_test import slowinc, gen_cluster
from distributed.dashboard.components.shared import (
Expand All @@ -21,16 +22,16 @@ def test_basic(Component):


@gen_cluster(client=True, clean_kwargs={"threads": False})
def test_profile_plot(c, s, a, b):
async def test_profile_plot(c, s, a, b):
p = ProfilePlot()
assert not p.source.data["left"]
yield c.map(slowinc, range(10), delay=0.05)
await c.gather(c.map(slowinc, range(10), delay=0.05))
p.update(a.profile_recent)
assert len(p.source.data["left"]) >= 1


@gen_cluster(client=True, clean_kwargs={"threads": False})
def test_profile_time_plot(c, s, a, b):
async def test_profile_time_plot(c, s, a, b):
from bokeh.io import curdoc

sp = ProfileTimePlot(s, doc=curdoc())
Expand All @@ -42,7 +43,7 @@ def test_profile_time_plot(c, s, a, b):
assert len(sp.source.data["left"]) <= 1
assert len(ap.source.data["left"]) <= 1

yield c.map(slowinc, range(10), delay=0.05)
await c.gather(c.map(slowinc, range(10), delay=0.05))
ap.trigger_update()
sp.trigger_update()
yield gen.sleep(0.05)
await asyncio.sleep(0.05)
Loading