Exemplo n.º 1
0
    def test_003(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=0)

        client  = MqttClient("rabbit:{seq}", keepalive=2)
        will    = {'topic': '/node/disconnect', 'message': client.clientid()}
        client.connect(version=4, will=will)

        time.sleep(1)
        client.send_pingreq()
        evt = monitor.recv()
        if monitor.recv() != None:
            debug(evt)
            return False

        time.sleep(4)
        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message']:
            debug(evt)
            return False

        monitor.disconnect()
        return True
Exemplo n.º 2
0
    def test_102(self):
        c = MqttClient("conformity:{seq}")
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect(('127.0.0.1', 1883))
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            sock.setblocking(0)
        except Exception as e:
            debug(e)
            return False

        c._c.sock = sock
        c.forge(
            NC.CMD_CONNECT,
            0,
            [
                ('string', 'MqTt'),
                ('byte', NC.PROTOCOL_VERSION_4),
                ('string', 'ff')  # client id
            ],
            send=True)

        try:
            c.send_pingreq()
            c._c.sock.getpeername()
        except socket.error as e:
            return True

        debug("connection still alive")
        return False
Exemplo n.º 3
0
    def test_003(self):
        monitor = MqttClient("monitor:{seq}", connect=4)
        # NOTE: '/' prefix skips $ messages
        # TODO: remove it when '$' filter will be impl.
        monitor.subscribe("/#", qos=0)

        client = MqttClient("rabbit:{seq}", keepalive=2)
        will = {'topic': '/node/disconnect', 'message': client.clientid()}
        client.connect(version=4, will=will)

        time.sleep(1)
        client.send_pingreq()
        evt = monitor.recv()
        if monitor.recv() != None:
            debug(evt)
            return False

        time.sleep(4)
        evt = monitor.recv()
        if not isinstance(evt, EventPublish) or evt.msg.topic != will['topic'] or \
                evt.msg.payload != will['message']:
            debug(evt)
            return False

        monitor.disconnect()
        return True
Exemplo n.º 4
0
    def test_102(self):
        c = MqttClient("conformity:{seq}")
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect(('127.0.0.1', 1883))
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            sock.setblocking(0)
        except Exception as e:
            debug(e)
            return False

        c._c.sock = sock
        c.forge(NC.CMD_CONNECT, 0, [
            ('string', 'MqTt'),
            ('byte'  , NC.PROTOCOL_VERSION_4),
            ('string', 'ff') # client id
        ], send=True)

        try:
            c.send_pingreq()
            c._c.sock.getpeername()
        except socket.error as e:
            return True

        debug("connection still alive")
        return False
Exemplo n.º 5
0
    def test_020(self):
        c = MqttClient("reg:{seq}", connect=4)
        e = c.send_pingreq()
        c.disconnect()

        return isinstance(e, EventPingResp)
Exemplo n.º 6
0
    def test_020(self):
        c = MqttClient("reg:{seq}", connect=4)
        e = c.send_pingreq()
        c.disconnect()

        return isinstance(e, EventPingResp)