def test_compute_who_has(current_loop): @gen.coroutine def f(): s = Scheduler() s.listen(0) x = Worker(s.ip, s.port, ip='127.0.0.1') y = Worker(s.ip, s.port, ip='127.0.0.1') z = Worker(s.ip, s.port, ip='127.0.0.1') x.data['a'] = 1 y.data['a'] = 2 yield [x._start(), y._start(), z._start()] zz = rpc(ip=z.ip, port=z.port) yield zz.compute(function=dumps(inc), args=dumps(('a',)), who_has={'a': [x.address]}, key='b') assert z.data['b'] == 2 if 'a' in z.data: del z.data['a'] yield zz.compute(function=dumps(inc), args=dumps(('a',)), who_has={'a': [y.address]}, key='c') assert z.data['c'] == 3 yield [x._close(), y._close(), z._close()] zz.close_streams() current_loop.run_sync(f, timeout=5)
def test_worker_waits_for_center_to_come_up(current_loop): @gen.coroutine def f(): w = Worker('127.0.0.1', 8007, ip='127.0.0.1') yield w._start() try: current_loop.run_sync(f, timeout=4) except TimeoutError: pass
def test_worker_with_port_zero(current_loop): @gen.coroutine def f(): c = Center('127.0.0.1') c.listen(8007) w = Worker(c.ip, c.port, ip='127.0.0.1') yield w._start() assert isinstance(w.port, int) assert w.port > 1024 current_loop.run_sync(f)
def test_dask_submit_cli_writes_traceback_to_stdout(current_loop, tmpdir, invalid_python_script): @gen.coroutine def test(): remote_client = RemoteClient(ip='127.0.0.1', local_dir=str(tmpdir)) yield remote_client._start() out, err = yield _submit('127.0.0.1:{0}'.format(remote_client.port), str(invalid_python_script)) assert b'Traceback' in err yield remote_client._close() current_loop.run_sync(test, timeout=5)
def test_remote_client_uploads_a_file(current_loop, tmpdir, ): @gen.coroutine def test(): remote_client = RemoteClient(ip='127.0.0.1', local_dir=str(tmpdir)) yield remote_client._start(0) remote_process = rpc(ip='127.0.0.1', port=remote_client.port) upload = yield remote_process.upload_file(filename='script.py', file_payload='x=1') assert upload == {'status': 'OK', 'nbytes': 3} assert tmpdir.join('script.py').read() == "x=1" yield remote_client._close() current_loop.run_sync(test, timeout=5)
def test_remote_client_execution_outputs_stderr(current_loop, tmpdir, invalid_python_script): @gen.coroutine def test(): remote_client = RemoteClient(ip='127.0.0.1', local_dir=str(tmpdir)) yield remote_client._start(0) rr = rpc(ip='127.0.0.1', port=remote_client.port) yield rr.upload_file(filename='script.py', file_payload='a+1') message = yield rr.execute(filename='script.py') assert b'\'a\' is not defined' in message['stderr'] assert message['returncode'] == 1 yield remote_client._close() current_loop.run_sync(test, timeout=5)
def test_remote_client_execution_outputs_to_stdout(current_loop, tmpdir): @gen.coroutine def test(): remote_client = RemoteClient(ip='127.0.0.1', local_dir=str(tmpdir)) yield remote_client._start(0) rr = rpc(ip='127.0.0.1', port=remote_client.port) yield rr.upload_file(filename='script.py', file_payload='print("hello world!")') message = yield rr.execute(filename='script.py') assert message['stdout'] == b'hello world!' + os.linesep.encode() assert message['returncode'] == 0 yield remote_client._close() current_loop.run_sync(test, timeout=5)
def test_remote_client_execution_outputs_to_stdout(current_loop, tmpdir): @gen.coroutine def test(): remote_client = RemoteClient(ip='127.0.0.1', local_dir=str(tmpdir)) yield remote_client._start(0) rr = rpc(ip='127.0.0.1', port=remote_client.port) yield rr.upload_file(filename='script.py', file_payload='print("hello world!")') message = yield rr.execute(filename='script.py') assert message['stdout'] == b'hello world!\n' assert message['returncode'] == 0 yield remote_client._close() current_loop.run_sync(test, timeout=5)