Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed May 11, 2019
1 parent 53b372a commit cbf1e28
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
import mqttools


async def broker_main(listener):
async with listener:
try:
await listener.serve_forever()
except asyncio.CancelledError:
pass


class ClientTest(unittest.TestCase):

def test_connack_timeout(self):
Expand All @@ -16,13 +24,6 @@ def on_client_connected(reader, writer):

listener = await asyncio.start_server(on_client_connected, 'localhost', 0)

async def broker_main():
async with listener:
try:
await listener.serve_forever()
except asyncio.CancelledError:
pass

async def client_main():
client = mqttools.Client(*listener.sockets[0].getsockname(),
'connack',
Expand All @@ -33,7 +34,8 @@ async def client_main():

listener.close()

await asyncio.wait_for(asyncio.gather(broker_main(), client_main()), 1)
await asyncio.wait_for(
asyncio.gather(broker_main(listener), client_main()), 1)

def test_subscribe_timeout(self):
asyncio.run(self.subscribe_timeout())
Expand All @@ -45,13 +47,6 @@ def on_client_connected(reader, writer):

listener = await asyncio.start_server(on_client_connected, 'localhost', 0)

async def broker_main():
async with listener:
try:
await listener.serve_forever()
except asyncio.CancelledError:
pass

async def client_main():
client = mqttools.Client(*listener.sockets[0].getsockname(),
'suback',
Expand All @@ -63,7 +58,8 @@ async def client_main():

listener.close()

await asyncio.wait_for(asyncio.gather(broker_main(), client_main()), 1)
await asyncio.wait_for(
asyncio.gather(broker_main(listener), client_main()), 1)

def test_unsubscribe_timeout(self):
asyncio.run(self.unsubscribe_timeout())
Expand All @@ -75,13 +71,6 @@ def on_client_connected(reader, writer):

listener = await asyncio.start_server(on_client_connected, 'localhost', 0)

async def broker_main():
async with listener:
try:
await listener.serve_forever()
except asyncio.CancelledError:
pass

async def client_main():
client = mqttools.Client(*listener.sockets[0].getsockname(),
'unsuback',
Expand All @@ -93,7 +82,8 @@ async def client_main():

listener.close()

await asyncio.wait_for(asyncio.gather(broker_main(), client_main()), 1)
await asyncio.wait_for(
asyncio.gather(broker_main(listener), client_main()), 1)

def test_client_id(self):
client = mqttools.Client('localhost', 0)
Expand Down

0 comments on commit cbf1e28

Please sign in to comment.