Make PipeIOServer API more consistent with clients

This commit is contained in:
Kristóf Tóth 2019-04-17 14:10:47 +02:00
parent d12c9807f5
commit 024204e439
3 changed files with 8 additions and 8 deletions

View File

@ -5,7 +5,7 @@ from pipe_io_server import PipeIOServer
class EchoPipeIOServer(PipeIOServer):
def handle_message(self, message):
self.send(message)
self.send_message(message)
if __name__ == "__main__":

View File

@ -37,7 +37,7 @@ class PipeIOServer(ABC, Thread):
def handle_message(self, message):
raise NotImplementedError()
def send(self, message):
def send_message(self, message):
self._writer_thread.write(message)
@terminate_process_on_failure

View File

@ -63,7 +63,7 @@ class IOPipes:
self.in_pipe.close()
self.out_pipe.close()
def send(self, message):
def send_message(self, message):
self.in_pipe.write(message + b'\n')
self.in_pipe.flush()
@ -116,7 +116,7 @@ def test_out_pipe_closed_stop():
]
)
def test_io(io_pipes, test_data):
io_pipes.send(test_data.encode())
io_pipes.send_message(test_data.encode())
assert io_pipes.recv().decode() == test_data
@ -133,7 +133,7 @@ def test_io(io_pipes, test_data):
)
def test_io_large_data(io_pipes, test_data_size):
test_data = urandom(test_data_size).replace(b'\n', b'')
io_pipes.send(test_data)
io_pipes.send_message(test_data)
received_data = io_pipes.recv()
assert received_data == test_data
@ -141,13 +141,13 @@ def test_io_large_data(io_pipes, test_data_size):
def test_io_stress(io_pipes):
for _ in range(2222):
test_data = urandom(randint(1, 1024)).replace(b'\n', b'')
io_pipes.send(test_data)
io_pipes.send_message(test_data)
assert io_pipes.recv() == test_data
def test_io_newlines(io_pipes):
times = randint(1, 512)
io_pipes.send(b'\n' * times)
io_pipes.send_message(b'\n' * times)
for _ in range(times + 1): # IOPipes.send appends +1
assert io_pipes.recv() == b''
@ -169,5 +169,5 @@ def test_json_io(io_pipes):
f'{token_urlsafe(8)}': [token_urlsafe(4) for i in range(10)],
}
}
io_pipes.send(dumps(test_data).encode())
io_pipes.send_message(dumps(test_data).encode())
assert loads(io_pipes.recv()) == test_data