From ed951f7ce90649e85956398cdb242634e6f6b371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 29 Jul 2019 18:14:18 +0200 Subject: [PATCH] Fix test_stop (which was broken during a refactor) --- pipe_io_server/test_pipe_io_server.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pipe_io_server/test_pipe_io_server.py b/pipe_io_server/test_pipe_io_server.py index 942674a..7a21756 100644 --- a/pipe_io_server/test_pipe_io_server.py +++ b/pipe_io_server/test_pipe_io_server.py @@ -29,8 +29,8 @@ def get_test_init_params(): return join(here, 'in_pipe_tests'), join(here, 'out_pipe_tests') -def raise_if_thread_blocks(thread_target_function, unblock_function): - thread = Thread(target=thread_target_function) +def raise_if_thread_blocks(*, target, unblock_function): + thread = Thread(target=target) thread.start() unblock_function() thread.join(timeout=1) @@ -72,11 +72,22 @@ def test_run_creates_pipes(io_pipes): def test_stop(): pipe_io = EchoPipeIOServer(*get_test_init_params()) - def open_close_in_pipe(): - pipe_io.stop() - raise_if_thread_blocks(pipe_io.run, open_close_in_pipe) - for path in (pipe_io.in_pipe, pipe_io.out_pipe): - assert not exists(path) + pipe_io.start() + raise_if_thread_blocks(target=pipe_io.wait, unblock_function=pipe_io.stop) + + pipe_io = EchoPipeIOServer(*get_test_init_params()) + pipe_io.start() + with IOPipes(pipe_io.in_pipe, pipe_io.out_pipe) as iopipes: + raise_if_thread_blocks(target=pipe_io.wait, unblock_function=pipe_io.stop) + + pipe_io = EchoPipeIOServer(*get_test_init_params()) + pipe_io.start() + with IOPipes(pipe_io.in_pipe, pipe_io.out_pipe) as iopipes: + test_message = token_urlsafe(randint(128, 256)) + iopipes.send_message(test_message.encode()) + assert test_message == iopipes.recv().decode() + iopipes.send_message(test_message.encode()) + raise_if_thread_blocks(target=pipe_io.wait, unblock_function=pipe_io.stop) @pytest.mark.parametrize(