[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 26/27] python/aqmp: add LineProtocol tests
From: |
John Snow |
Subject: |
[PATCH v4 26/27] python/aqmp: add LineProtocol tests |
Date: |
Wed, 15 Sep 2021 12:29:54 -0400 |
Tests a real connect, a real accept, and really sending and receiving a
message over a UNIX socket.
Brings coverage of protocol.py up to ~93%.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/tests/protocol.py | 48 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/python/tests/protocol.py b/python/tests/protocol.py
index f0682d29ce..5cd7938be3 100644
--- a/python/tests/protocol.py
+++ b/python/tests/protocol.py
@@ -78,6 +78,25 @@ async def simulate_disconnect(self) -> None:
self._schedule_disconnect()
+class LineProtocol(AsyncProtocol[str]):
+ def __init__(self, name=None):
+ super().__init__(name)
+ self.rx_history = []
+
+ async def _do_recv(self) -> str:
+ raw = await self._readline()
+ msg = raw.decode()
+ self.rx_history.append(msg)
+ return msg
+
+ def _do_send(self, msg: str) -> None:
+ assert self._writer is not None
+ self._writer.write(msg.encode() + b'\n')
+
+ async def send_msg(self, msg: str) -> None:
+ await self._outgoing.put(msg)
+
+
def run_as_task(coro, allow_cancellation=False):
"""
Run a given coroutine as a task.
@@ -533,3 +552,32 @@ async def testConnectRequireDisconnecting(self):
" Call disconnect() to return to IDLE state."),
accept=False,
)
+
+
+class SimpleSession(TestBase):
+
+ def setUp(self):
+ super().setUp()
+ self.server = LineProtocol(type(self).__name__ + '-server')
+
+ async def _asyncSetUp(self):
+ await super()._asyncSetUp()
+ await self._watch_runstates(*self.GOOD_CONNECTION_STATES)
+
+ async def _asyncTearDown(self):
+ await self.proto.disconnect()
+ try:
+ await self.server.disconnect()
+ except EOFError:
+ pass
+ await super()._asyncTearDown()
+
+ @TestBase.async_test
+ async def testSmoke(self):
+ with TemporaryDirectory(suffix='.aqmp') as tmpdir:
+ sock = os.path.join(tmpdir, type(self.proto).__name__ + ".sock")
+ server_task = create_task(self.server.accept(sock))
+
+ # give the server a chance to start listening [...]
+ await asyncio.sleep(0)
+ await self.proto.connect(sock)
--
2.31.1
- [PATCH v4 14/27] python/aqmp: add well-known QMP object models, (continued)
- [PATCH v4 14/27] python/aqmp: add well-known QMP object models, John Snow, 2021/09/15
- [PATCH v4 16/27] python/pylint: disable too-many-function-args, John Snow, 2021/09/15
- [PATCH v4 17/27] python/aqmp: add QMP protocol support, John Snow, 2021/09/15
- [PATCH v4 19/27] python/aqmp: Add message routing to QMP protocol, John Snow, 2021/09/15
- [PATCH v4 20/27] python/aqmp: add execute() interfaces, John Snow, 2021/09/15
- [PATCH v4 15/27] python/aqmp: add QMP event support, John Snow, 2021/09/15
- [PATCH v4 18/27] python/pylint: disable no-member check, John Snow, 2021/09/15
- [PATCH v4 21/27] python/aqmp: add _raw() execution interface, John Snow, 2021/09/15
- [PATCH v4 23/27] python/aqmp: add scary message, John Snow, 2021/09/15
- [PATCH v4 22/27] python/aqmp: add asyncio_run compatibility wrapper, John Snow, 2021/09/15
- [PATCH v4 26/27] python/aqmp: add LineProtocol tests,
John Snow <=
- [PATCH v4 27/27] python/aqmp: Add Coverage.py support, John Snow, 2021/09/15
- [PATCH v4 24/27] python: bump avocado to v90.0, John Snow, 2021/09/15
- [PATCH v4 25/27] python/aqmp: add AsyncProtocol unit tests, John Snow, 2021/09/15
- Re: [PATCH v4 00/27] python: introduce Asynchronous QMP package, John Snow, 2021/09/20