Exemplo n.º 1
0
def test_sync_receive_messages():
    c = sync.SyncConn()
    c.connect("127.0.0.1", 4150)

    c.send(protocol.identify({'short_id': 'test', 'long_id': 'test.example'}))
    c.send(protocol.subscribe('test', 'ch'))

    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')
    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'

    for i in range(10):
        c.send(protocol.ready(1))
        body = b'{"data": {"test_key": %d}}' % i
        ts = int(time.time() * 1000 * 1000)
        mock_response_write_message(c, ts, 0, i, body)
        resp = c.read_response()
        unpacked = protocol.unpack_response(resp)
        assert unpacked[0] == protocol.FRAME_TYPE_MESSAGE
        msg = protocol.decode_message(unpacked[1])
        assert msg.timestamp == ts
        assert msg.id == b"%016d" % i
        assert msg.attempts == 0
        assert msg.body == body
Exemplo n.º 2
0
def test_sync_authenticate_subscribe():
    c = sync.SyncConn()
    c.connect("127.0.0.1", 4150)

    c.send(
        protocol.identify({
            'short_id': 'test',
            'long_id': 'test.example',
            'client_id': 'test',
            'hostname': 'test.example'
        }))
    c.send(protocol.subscribe('test', 'ch'))

    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')
    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'
Exemplo n.º 3
0
def test_sync_receive_messages():
    c = sync.SyncConn()
    c.connect("127.0.0.1", 4150)

    c.send(protocol.identify({'short_id': 'test', 'long_id': 'test.example',
                              'client_id': 'test', 'hostname': 'test.example'}))
    c.send(protocol.subscribe('test', 'ch'))

    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')
    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'

    for i in range(10):
        c.send(protocol.ready(1))
        body = ('{"data": {"test_key": %d}}' % i).encode()
        ts = int(time.time() * 1000 * 1000)
        mock_response_write_message(c, ts, 0, i, body)
        resp = c.read_response()
        unpacked = protocol.unpack_response(resp)
        assert unpacked[0] == protocol.FRAME_TYPE_MESSAGE
        msg = protocol.decode_message(unpacked[1])
        assert msg.timestamp == ts
        assert msg.id == ("%016d" % i).encode()
        assert msg.attempts == 0
        assert msg.body == body
Exemplo n.º 4
0
def test_sync_authenticate_subscribe():
    c = sync.SyncConn()
    c.connect("127.0.0.1", 4150)

    c.send(protocol.identify({'short_id': 'test', 'long_id': 'test.example'}))
    c.send(protocol.subscribe('test', 'ch'))

    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')
    mock_response_write(c, protocol.FRAME_TYPE_RESPONSE, b'OK')

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'

    resp = c.read_response()
    unpacked = protocol.unpack_response(resp)
    assert unpacked[0] == protocol.FRAME_TYPE_RESPONSE
    assert unpacked[1] == b'OK'
Exemplo n.º 5
0
 def _on_ready(*args, **kwargs):
     c.on('message', _on_message)
     c.send(protocol.subscribe(topic, 'ch'))
     c.send_rdy(5)
Exemplo n.º 6
0
 def _on_ready(*args, **kwargs):
     c.on('response', self.stop)
     c.send(protocol.subscribe(topic, 'ch'))
Exemplo n.º 7
0
 def _on_ready(*args, **kwargs):
     c.on('message', _on_message)
     c.send(protocol.subscribe(topic, 'ch'))
     c.send_rdy(5)
Exemplo n.º 8
0
 def _on_ready(*args, **kwargs):
     c.on('response', self.stop)
     c.send(protocol.subscribe(topic, 'ch'))
Exemplo n.º 9
0
 def _on_ready(*args, **kwargs):
     c.on("message", _on_message)
     c.send(protocol.subscribe(topic, "ch"))
     c.send_rdy(5)
Exemplo n.º 10
0
 def _on_ready(*args, **kwargs):
     c.on("response", self.stop)
     c.send(protocol.subscribe(topic, "ch"))