Example #1
0
def test_publish_and_pull(publisher: PubsubPublisher):
    publisher.publish(project_id, topic2, header_1, gzip.compress(b'[]'))
    subscriber = PubsubSubscriber(sub_client=pubsub_v1.SubscriberClient())
    for message in subscriber.pull(project_id, subscription2):
        header, data, id = subscriber.unpack_message(message)
        assert int(header['age']) == 2
        assert 'long_str' not in header
        subscriber.ack(project_id, subscription2, id)
Example #2
0
def test_check_messages():
    sub = PubsubSubscriber(sub_client=pubsub_v1.SubscriberClient())
    for message in sub.pull('x-i-a-test', 'xialib-sub-01'):
        header, data, id = sub.unpack_message(message)
        assert len(json.loads(gzip.decompress(data).decode())) == 2
        sub.ack('x-i-a-test', 'xialib-sub-01', id)