Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Apr 14, 2020
1 parent e07b9f8 commit 5d2566c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 52 deletions.
24 changes: 9 additions & 15 deletions distributed/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def test_map(c, s, a, b):

L4 = c.map(add, range(3), range(4))
results = yield c.gather(L4)
if sys.version_info[0] >= 3:
assert results == list(map(add, range(3), range(4)))
assert results == list(map(add, range(3), range(4)))

def f(x, y=10):
return x + y
Expand Down Expand Up @@ -1439,9 +1438,7 @@ def test_many_submits_spread_evenly(c, s, a, b):
def test_traceback(c, s, a, b):
x = c.submit(div, 1, 0)
tb = yield x.traceback()

if sys.version_info[0] >= 3:
assert any("x / y" in line for line in pluck(3, traceback.extract_tb(tb)))
assert any("x / y" in line for line in pluck(3, traceback.extract_tb(tb)))


@gen_cluster(client=True)
Expand All @@ -1468,12 +1465,11 @@ def test_gather_traceback(c, s, a, b):
def test_traceback_sync(c):
x = c.submit(div, 1, 0)
tb = x.traceback()
if sys.version_info[0] >= 3:
assert any(
"x / y" in line
for line in concat(traceback.extract_tb(tb))
if isinstance(line, str)
)
assert any(
"x / y" in line
for line in concat(traceback.extract_tb(tb))
if isinstance(line, str)
)

y = c.submit(inc, x)
tb2 = y.traceback()
Expand Down Expand Up @@ -2597,9 +2593,8 @@ def test_run_coroutine(c, s, a, b):
with pytest.raises(RuntimeError, match="hello"):
yield c.run(throws, 1)

if sys.version_info >= (3, 5):
results = yield c.run(asyncinc, 2, delay=0.01)
assert results == {a.address: 3, b.address: 3}
results = yield c.run(asyncinc, 2, delay=0.01)
assert results == {a.address: 3, b.address: 3}


def test_run_coroutine_sync(c, s, a, b):
Expand Down Expand Up @@ -5212,7 +5207,6 @@ def test_scatter_direct(s, a, b):
yield c.close()


@pytest.mark.skipif(sys.version_info[0] < 3, reason="cloudpickle Py27 issue")
@gen_cluster(client=True)
def test_unhashable_function(c, s, a, b):
d = {"a": 1}
Expand Down
1 change: 0 additions & 1 deletion distributed/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ def test_retire_workers_no_suspicious_tasks(c, s, a, b):
@pytest.mark.skipif(
sys.platform.startswith("win"), reason="file descriptors not really a thing"
)
@pytest.mark.skipif(sys.version_info < (3, 6), reason="intermittent failure")
@gen_cluster(client=True, nthreads=[], timeout=240)
def test_file_descriptors(c, s):
yield gen.sleep(0.1)
Expand Down
46 changes: 20 additions & 26 deletions distributed/tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ def test_tls_config_for_role():
sec.get_tls_config_for_role("supervisor")


def assert_many_ciphers(ctx):
assert len(ctx.get_ciphers()) > 2 # Most likely


def test_connection_args():
def basic_checks(ctx):
assert ctx.verify_mode == ssl.CERT_REQUIRED
assert ctx.check_hostname is False

def many_ciphers(ctx):
if sys.version_info >= (3, 6):
assert len(ctx.get_ciphers()) > 2 # Most likely

c = {
"distributed.comm.tls.ca-file": ca_file,
"distributed.comm.tls.scheduler.key": key1,
Expand All @@ -171,12 +171,12 @@ def many_ciphers(ctx):
assert not d["require_encryption"]
ctx = d["ssl_context"]
basic_checks(ctx)
many_ciphers(ctx)
assert_many_ciphers(ctx)

d = sec.get_connection_args("worker")
ctx = d["ssl_context"]
basic_checks(ctx)
many_ciphers(ctx)
assert_many_ciphers(ctx)

# No cert defined => no TLS
d = sec.get_connection_args("client")
Expand All @@ -193,24 +193,19 @@ def many_ciphers(ctx):
assert d["require_encryption"]
ctx = d["ssl_context"]
basic_checks(ctx)
if sys.version_info >= (3, 6):
supported_ciphers = ctx.get_ciphers()
tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]]
assert len(tls_12_ciphers) == 1
tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]]
if len(tls_13_ciphers):
assert len(tls_13_ciphers) == 3

supported_ciphers = ctx.get_ciphers()
tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]]
assert len(tls_12_ciphers) == 1
tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]]
assert len(tls_13_ciphers) in (0, 3)


def test_listen_args():
def basic_checks(ctx):
assert ctx.verify_mode == ssl.CERT_REQUIRED
assert ctx.check_hostname is False

def many_ciphers(ctx):
if sys.version_info >= (3, 6):
assert len(ctx.get_ciphers()) > 2 # Most likely

c = {
"distributed.comm.tls.ca-file": ca_file,
"distributed.comm.tls.scheduler.key": key1,
Expand All @@ -224,12 +219,12 @@ def many_ciphers(ctx):
assert not d["require_encryption"]
ctx = d["ssl_context"]
basic_checks(ctx)
many_ciphers(ctx)
assert_many_ciphers(ctx)

d = sec.get_listen_args("worker")
ctx = d["ssl_context"]
basic_checks(ctx)
many_ciphers(ctx)
assert_many_ciphers(ctx)

# No cert defined => no TLS
d = sec.get_listen_args("client")
Expand All @@ -246,13 +241,12 @@ def many_ciphers(ctx):
assert d["require_encryption"]
ctx = d["ssl_context"]
basic_checks(ctx)
if sys.version_info >= (3, 6):
supported_ciphers = ctx.get_ciphers()
tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]]
assert len(tls_12_ciphers) == 1
tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]]
if len(tls_13_ciphers):
assert len(tls_13_ciphers) == 3

supported_ciphers = ctx.get_ciphers()
tls_12_ciphers = [c for c in supported_ciphers if "TLSv1.2" in c["description"]]
assert len(tls_12_ciphers) == 1
tls_13_ciphers = [c for c in supported_ciphers if "TLSv1.3" in c["description"]]
assert len(tls_13_ciphers) in (0, 3)


@pytest.mark.asyncio
Expand Down
1 change: 0 additions & 1 deletion distributed/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def test_timeout_get(c, s, a, b):
assert result == 1


@pytest.mark.skipif(sys.version_info[0] == 2, reason="Multi-client issues")
@pytest.mark.slow
@gen_cluster(client=True, nthreads=[("127.0.0.1", 2)] * 5, Worker=Nanny, timeout=None)
def test_race(c, s, *workers):
Expand Down
13 changes: 4 additions & 9 deletions distributed/tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ def reset(self):
with pytest.raises(ZeroDivisionError):
yield y

if sys.version_info[0] >= 3:
tb = yield y._traceback()
assert any(
"1 / 0" in line for line in pluck(3, traceback.extract_tb(tb)) if line
)
tb = yield y._traceback()
assert any(
"1 / 0" in line for line in pluck(3, traceback.extract_tb(tb)) if line
)
assert "Compute Failed" in hdlr.messages["warning"][0]
logger.setLevel(old_level)

Expand Down Expand Up @@ -473,9 +472,6 @@ def f(dask_worker=None):

@gen_cluster(client=True)
def test_run_coroutine_dask_worker(c, s, a, b):
if sys.version_info < (3,) and tornado.version_info < (4, 5):
pytest.skip("test needs Tornado 4.5+ on Python 2.7")

@gen.coroutine
def f(dask_worker=None):
yield gen.sleep(0.001)
Expand Down Expand Up @@ -586,7 +582,6 @@ def test_clean(c, s, a, b):
assert not c


@pytest.mark.skipif(sys.version_info[:2] == (3, 4), reason="mul bytes fails")
@gen_cluster(client=True)
def test_message_breakup(c, s, a, b):
n = 100000
Expand Down

0 comments on commit 5d2566c

Please sign in to comment.