This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
ipc-unix/tests/test_simple.py

33 lines
985 B
Python
Raw Normal View History

2018-12-07 20:35:34 +00:00
from unittest import TestCase
2018-12-07 20:44:31 +00:00
2018-12-08 14:23:16 +00:00
from ipc_unix.simple import Client
from ipc_unix.utils import BUFFER_SIZE
2018-12-07 23:18:29 +00:00
from tests import EchoServer, get_temp_file_path
2018-12-07 20:35:34 +00:00
2018-12-07 23:34:59 +00:00
class SimpleServerTestCase(TestCase):
2018-12-07 20:35:34 +00:00
def setUp(self):
2018-12-07 23:18:29 +00:00
self.socket_path = get_temp_file_path()
2018-12-07 20:35:34 +00:00
self.server = EchoServer(self.socket_path)
self.server.serve_in_thread()
2018-12-08 14:23:16 +00:00
self.client = Client(self.socket_path)
2018-12-07 20:35:34 +00:00
def tearDown(self):
2018-12-08 13:07:51 +00:00
self.server.close()
2018-12-07 20:35:34 +00:00
def test_sending_dict(self):
data = {"foo": "bar"}
2018-12-08 14:23:16 +00:00
response = self.client.send(data)
2018-12-07 20:35:34 +00:00
self.assertEqual(response, data)
def test_sending_full_buffer(self):
data = {"foo" + str(i): i for i in range(BUFFER_SIZE)}
2018-12-08 14:23:16 +00:00
response = self.client.send(data)
2018-12-07 20:35:34 +00:00
self.assertEqual(response, data)
def test_multiple_send_to_same_server(self):
data = {"foo": "bar"}
for _ in range(10):
2018-12-08 14:23:16 +00:00
response = self.client.send(data)
2018-12-07 20:35:34 +00:00
self.assertEqual(response, data)