Пример #1
0
async def test_client_publish_dup(broker, event_loop):
    conn_reader, conn_writer = await asyncio.open_connection("127.0.0.1",
                                                             1883,
                                                             loop=event_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)
    await connect.to_stream(writer)
    await ConnackPacket.from_stream(reader)

    publish_1 = PublishPacket.build("/test", b"data", 1, False, QOS_2, False)
    await publish_1.to_stream(writer)
    asyncio.ensure_future(PubrecPacket.from_stream(reader), loop=event_loop)

    await asyncio.sleep(2)

    publish_dup = PublishPacket.build("/test", b"data", 1, True, QOS_2, False)
    await publish_dup.to_stream(writer)
    await PubrecPacket.from_stream(reader)
    pubrel = PubrelPacket.build(1)
    await pubrel.to_stream(writer)
    await PubcompPacket.from_stream(reader)

    disconnect = DisconnectPacket()
    await disconnect.to_stream(writer)
Пример #2
0
        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)
Пример #3
0
        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)
Пример #4
0
        async def test_coro():
            try:
                broker = Broker(
                    self._test_config, plugin_namespace="hbmqtt.test.plugins"
                )
                await broker.start()
                self.assertTrue(broker.transitions.is_started())

                conn_reader, conn_writer = await asyncio.open_connection(
                    "127.0.0.1", self._test_port, 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)
                await connect.to_stream(writer)
                await ConnackPacket.from_stream(reader)

                publish_1 = PublishPacket.build(
                    "/test", b"data", 1, False, QOS_2, False
                )
                await publish_1.to_stream(writer)
                asyncio.ensure_future(PubrecPacket.from_stream(reader), loop=self.loop)

                await asyncio.sleep(2)

                publish_dup = PublishPacket.build(
                    "/test", b"data", 1, True, QOS_2, False
                )
                await publish_dup.to_stream(writer)
                await PubrecPacket.from_stream(reader)
                pubrel = PubrelPacket.build(1)
                await pubrel.to_stream(writer)
                await PubcompPacket.from_stream(reader)

                disconnect = DisconnectPacket()
                await disconnect.to_stream(writer)

                await asyncio.sleep(0.1)
                await broker.shutdown()
                future.set_result(True)
            except Exception as ae:
                future.set_exception(ae)