Skip to content

Commit

Permalink
mqtt line test
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Oct 2, 2017
1 parent 5d23c65 commit 3c5c231
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/test_mqtt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""mqtt line tests
"""
import logging
import asyncio
import pytest
Expand All @@ -11,7 +13,7 @@
logging.basicConfig(level=logging.DEBUG)
LOG = logging.getLogger()

config = {
CONFIG = {
'listeners': {
'default': {
'type': 'tcp',
Expand All @@ -31,16 +33,18 @@ def cancel_tasks_old():
task.cancel()


# pylint: disable=W0613
@pytest.mark.asyncio
async def test_mqtt(event_loop):

""" mqtt line linked to tcp and ws lines
"""
topic = "a/b"

# start broker
broker = hbmqtt.broker.Broker(config)
broker = hbmqtt.broker.Broker(CONFIG)
await broker.start()

# start the junction
# start the junction
port1 = 1883
port2 = 3001
port3 = 9000
Expand All @@ -56,30 +60,29 @@ async def test_mqtt(event_loop):

await asyncio.sleep(0.1)

#start the tcp client
#start tcp client
channel = await ns.connect('0.0.0.0', port2)

#start the ws client
#start ws client
ws_socket = await ns.wsconnect('0.0.0.0', port3)

#start the mqtt client
#start mqtt client
mqtt_client = hbmqtt.client.MQTTClient()
await mqtt_client.connect('mqtt://127.0.0.1')

await mqtt_client.subscribe([(topic, QOS_1)])
await mqtt_client.subscribe([('hb/'+topic, QOS_1)])

#send a message from the tcp client
#send a message from tcp client
ascii_msg = b'pippo\n'
await ns.msg_send(channel, ascii_msg)

json_msg = "'JSON_MSG'"
await ws_socket.send(json_msg)

#wait the mqtt packet
#wait for a mqtt packet
message = await mqtt_client.deliver_message()
packet = message.publish_packet

await mqtt_client.publish('hb/{}'.format(topic), b'PLUTO\n', QOS_1)
LOG.debug("received mqtt message: %s", message.publish_packet.payload.data)
await mqtt_client.publish(topic, b'PLUTO\n', QOS_1)

response = await ns.msg_receive(channel)

Expand All @@ -90,4 +93,3 @@ async def test_mqtt(event_loop):
await ns.junction.shutdown()
await broker.shutdown()
cancel_tasks()

0 comments on commit 3c5c231

Please sign in to comment.