kopia lustrzana https://github.com/Yakifo/amqtt
Randomize packet ID
rodzic
8dab60a444
commit
dd1a5bde6a
|
@ -333,7 +333,7 @@ class ProtocolHandler:
|
|||
# Wait PUBREL
|
||||
if app_message.packet_id in self._pubrel_waiters:
|
||||
# PUBREL waiter already exists for this packet ID
|
||||
message = "Can't add PUBREC waiter, a waiter already exists for message Id '%s'" \
|
||||
message = "Can't add PUBREL waiter, a waiter already exists for message Id '%s'" \
|
||||
% app_message.packet_id
|
||||
self.logger.warning(message)
|
||||
raise HBMQTTException(message)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import unittest
|
||||
import asyncio
|
||||
import logging
|
||||
import random
|
||||
from hbmqtt.plugins.manager import PluginManager
|
||||
from hbmqtt.session import Session, OutgoingApplicationMessage, IncomingApplicationMessage
|
||||
from hbmqtt.mqtt.protocol.handler import ProtocolHandler
|
||||
|
@ -20,6 +21,10 @@ logging.basicConfig(level=logging.DEBUG, format=formatter)
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def rand_packet_id():
|
||||
return random.randint(0, 65535)
|
||||
|
||||
|
||||
def adapt(reader, writer):
|
||||
return StreamReaderAdapter(reader), StreamWriterAdapter(writer)
|
||||
|
||||
|
@ -211,7 +216,7 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
def test_receive_qos0(self):
|
||||
@asyncio.coroutine
|
||||
def server_mock(reader, writer):
|
||||
packet = PublishPacket.build('/topic', b'test_data', 1, False, QOS_0, False)
|
||||
packet = PublishPacket.build('/topic', b'test_data', rand_packet_id(), False, QOS_0, False)
|
||||
yield from packet.to_stream(writer)
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -249,7 +254,7 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
@asyncio.coroutine
|
||||
def server_mock(reader, writer):
|
||||
try:
|
||||
packet = PublishPacket.build('/topic', b'test_data', 1, False, QOS_1, False)
|
||||
packet = PublishPacket.build('/topic', b'test_data', rand_packet_id(), False, QOS_1, False)
|
||||
yield from packet.to_stream(writer)
|
||||
puback = yield from PubackPacket.from_stream(reader)
|
||||
self.assertIsNotNone(puback)
|
||||
|
@ -294,7 +299,7 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
@asyncio.coroutine
|
||||
def server_mock(reader, writer):
|
||||
try:
|
||||
packet = PublishPacket.build('/topic', b'test_data', 2, False, QOS_2, False)
|
||||
packet = PublishPacket.build('/topic', b'test_data', rand_packet_id(), False, QOS_2, False)
|
||||
yield from packet.to_stream(writer)
|
||||
pubrec = yield from PubrecPacket.from_stream(reader)
|
||||
self.assertIsNotNone(pubrec)
|
||||
|
@ -394,7 +399,7 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
self.handler = None
|
||||
self.session = Session()
|
||||
message = OutgoingApplicationMessage(1, '/topic', QOS_1, b'test_data', False)
|
||||
message.publish_packet = PublishPacket.build('/topic', b'test_data', 1, False, QOS_1, False)
|
||||
message.publish_packet = PublishPacket.build('/topic', b'test_data', rand_packet_id(), False, QOS_1, False)
|
||||
self.session.inflight_out[1] = message
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
|
||||
|
@ -442,7 +447,7 @@ class ProtocolHandlerTest(unittest.TestCase):
|
|||
self.handler = None
|
||||
self.session = Session()
|
||||
message = OutgoingApplicationMessage(1, '/topic', QOS_2, b'test_data', False)
|
||||
message.publish_packet = PublishPacket.build('/topic', b'test_data', 1, False, QOS_2, False)
|
||||
message.publish_packet = PublishPacket.build('/topic', b'test_data', rand_packet_id(), False, QOS_2, False)
|
||||
self.session.inflight_out[1] = message
|
||||
future = asyncio.Future(loop=self.loop)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue