test/api: fix hang on server shutdown

If the server was fully hung, then these shutdown steps were also stuck.
This commit is contained in:
Dan Bungert 2021-10-07 13:12:40 -06:00
parent b95ba87440
commit 1c5ed98430
1 changed files with 7 additions and 5 deletions

View File

@ -107,12 +107,14 @@ class Server(Client):
self.server_task = asyncio.create_task(self.proc.communicate())
async def close(self):
await self.server_shutdown()
await self.server_task
try:
self.proc.kill()
except ProcessLookupError:
pass
await asyncio.wait_for(self.server_shutdown(), timeout=2.0)
await asyncio.wait_for(self.server_task, timeout=1.0)
finally:
try:
self.proc.kill()
except ProcessLookupError:
pass
class TestAPI(unittest.IsolatedAsyncioTestCase):