util/jsoncomm: add pair constructor method

Add a new constructor method, `Socket.new_pair`, to create a pair
of connected sockets (via `socketpair`) and wrap both sides via
`jsoncomm.Socket`.
Add a simple test to check it.
This commit is contained in:
Christian Kellner 2021-05-29 13:48:47 +02:00 committed by Tom Gundersen
parent a8fcda8348
commit 0447b00dfc
2 changed files with 28 additions and 0 deletions

View file

@ -176,3 +176,13 @@ class TestUtilJsonComm(unittest.TestCase):
conn = listener.accept()
self.assertIsNone(conn)
def test_socket_pair(self):
#
# Test creating a socket pair and sending, receiving of a simple message
a, b = jsoncomm.Socket.new_pair()
ping = {"osbuild": "yes"}
a.send(ping)
pong, _, _ = b.recv()
self.assertEqual(ping, pong)