Unverified Commit a3f4831d authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[tests][dask] make find-open-port test more reliable (#3993)

* [dask] make find-open-port test more reliable

* use listen_port fixture

* Apply suggestions from code review
parent 5321fef6
......@@ -885,27 +885,27 @@ def test_model_and_local_version_are_picklable_whether_or_not_client_set_explici
assert_eq(preds_orig_local, preds_loaded_model_local)
def test_find_open_port_works():
def test_find_open_port_works(listen_port):
worker_ip = '127.0.0.1'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((worker_ip, 12400))
s.bind((worker_ip, listen_port))
new_port = lgb.dask._find_open_port(
worker_ip=worker_ip,
local_listen_port=12400,
local_listen_port=listen_port,
ports_to_skip=set()
)
assert new_port == 12401
assert listen_port < new_port < listen_port + 1000
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s_1:
s_1.bind((worker_ip, 12400))
s_1.bind((worker_ip, listen_port))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s_2:
s_2.bind((worker_ip, 12401))
s_2.bind((worker_ip, listen_port + 1))
new_port = lgb.dask._find_open_port(
worker_ip=worker_ip,
local_listen_port=12400,
local_listen_port=listen_port,
ports_to_skip=set()
)
assert new_port == 12402
assert listen_port + 1 < new_port < listen_port + 1000
def test_warns_and_continues_on_unrecognized_tree_learner(client):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment