def test_coro(): try: broker = Broker(test_config, plugin_namespace="hbmqtt.test.plugins") yield from broker.start() self.assertTrue(broker.transitions.is_started()) conn_reader, conn_writer = \ yield from asyncio.open_connection('127.0.0.1', 1883, loop=self.loop) reader = StreamReaderAdapter(conn_reader) writer = StreamWriterAdapter(conn_writer) vh = ConnectVariableHeader() payload = ConnectPayload() vh.keep_alive = 10 vh.clean_session_flag = False vh.will_retain_flag = False payload.client_id = 'test_id' connect = ConnectPacket(vh=vh, payload=payload) yield from connect.to_stream(writer) yield from ConnackPacket.from_stream(reader) publish_1 = PublishPacket.build('/test', b'data', 1, False, QOS_2, False) yield from publish_1.to_stream(writer) asyncio.ensure_future(PubrecPacket.from_stream(reader), loop=self.loop) yield from asyncio.sleep(2) publish_dup = PublishPacket.build('/test', b'data', 1, True, QOS_2, False) yield from publish_dup.to_stream(writer) yield from PubrecPacket.from_stream(reader) pubrel = PubrelPacket.build(1) yield from pubrel.to_stream(writer) yield from PubcompPacket.from_stream(reader) disconnect = DisconnectPacket() yield from disconnect.to_stream(writer) yield from asyncio.sleep(0.1) yield from broker.shutdown() future.set_result(True) except Exception as ae: future.set_exception(ae)
def test_coro(): try: broker = Broker(test_config, plugin_namespace="hbmqtt.test.plugins") yield from broker.start() self.assertTrue(broker.transitions.is_started()) conn_reader, conn_writer = \ yield from asyncio.open_connection('localhost', 1883, loop=self.loop) reader = StreamReaderAdapter(conn_reader) writer = StreamWriterAdapter(conn_writer) vh = ConnectVariableHeader() payload = ConnectPayload() vh.keep_alive = 10 vh.clean_session_flag = False vh.will_retain_flag = False vh.will_flag = True vh.will_qos = QOS_0 payload.client_id = 'test_id' payload.will_message = b'test' payload.will_topic = '/topic' connect = ConnectPacket(vh=vh, payload=payload) yield from connect.to_stream(writer) yield from ConnackPacket.from_stream(reader) yield from asyncio.sleep(0.1) disconnect = DisconnectPacket() yield from disconnect.to_stream(writer) yield from asyncio.sleep(0.1) yield from broker.shutdown() self.assertTrue(broker.transitions.is_stopped()) self.assertDictEqual(broker._sessions, {}) future.set_result(True) except Exception as ae: future.set_exception(ae)
def test_coro(): try: broker = Broker(test_config, plugin_namespace="hbmqtt.test.plugins") yield from broker.start() self.assertTrue(broker.transitions.is_started()) conn_reader, conn_writer = \ yield from asyncio.open_connection('127.0.0.1', 1883, loop=self.loop) reader = StreamReaderAdapter(conn_reader) writer = StreamWriterAdapter(conn_writer) vh = ConnectVariableHeader() payload = ConnectPayload() vh.keep_alive = 10 vh.clean_session_flag = False vh.will_retain_flag = False vh.will_flag = True vh.will_qos = QOS_0 payload.client_id = 'test_id' payload.will_message = b'test' payload.will_topic = '/topic' connect = ConnectPacket(vh=vh, payload=payload) yield from connect.to_stream(writer) yield from ConnackPacket.from_stream(reader) yield from asyncio.sleep(0.1) disconnect = DisconnectPacket() yield from disconnect.to_stream(writer) yield from asyncio.sleep(0.1) yield from broker.shutdown() self.assertTrue(broker.transitions.is_stopped()) self.assertDictEqual(broker._sessions, {}) future.set_result(True) except Exception as ae: future.set_exception(ae)