mirror of https://github.com/celery/kombu.git
Initial redis integration tests implementation
This commit is contained in:
parent
1b89912a83
commit
75667082e0
21
.travis.yml
21
.travis.yml
|
@ -75,6 +75,27 @@ jobs:
|
|||
- python: pypy3.5-7.0
|
||||
<<: *integration_job
|
||||
env: TOXENV=pypy3-integration-py-amqp
|
||||
- python: 2.7
|
||||
<<: *integration_job
|
||||
env: TOXENV=2.7-integration-redis
|
||||
- python: 3.5
|
||||
<<: *integration_job
|
||||
env: TOXENV=3.5-integration-redis
|
||||
- python: 3.6
|
||||
<<: *integration_job
|
||||
env: TOXENV=3.6-integration-redis
|
||||
- python: 3.7
|
||||
<<: *integration_job
|
||||
env: TOXENV=3.7-linux-integration-redis
|
||||
- python: 3.8
|
||||
<<: *integration_job
|
||||
env: TOXENV=3.8-linux-integration-redis
|
||||
- python: pypy2.7-7.1.1
|
||||
<<: *integration_job
|
||||
env: TOXENV=pypy-integration-redis
|
||||
- python: pypy3.5-7.0
|
||||
<<: *integration_job
|
||||
env: TOXENV=pypy3-integration-redis
|
||||
|
||||
install:
|
||||
- pip --disable-pip-version-check install -U pip setuptools wheel | cat
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from contextlib import closing
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import kombu
|
||||
|
||||
def get_connection(
|
||||
hostname, port, vhost):
|
||||
return kombu.Connection('redis://{}:{}'.format(hostname, port))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def connection(request):
|
||||
# this fixture yields plain connections to broker and TLS encrypted
|
||||
return get_connection(
|
||||
hostname=os.environ.get('REDIS_HOST', 'localhost'),
|
||||
port=os.environ.get('REDIS_6379_TCP', '6379'),
|
||||
vhost=getattr(
|
||||
request.config, "slaveinput", {}
|
||||
).get("slaveid", None),
|
||||
)
|
||||
|
||||
@pytest.mark.env('redis')
|
||||
@pytest.mark.flaky(reruns=5, reruns_delay=2)
|
||||
def test_connect(connection):
|
||||
connection.connect()
|
||||
connection.close()
|
||||
|
||||
@pytest.mark.env('redis')
|
||||
@pytest.mark.flaky(reruns=5, reruns_delay=2)
|
||||
def test_publish_consume(connection):
|
||||
test_queue = kombu.Queue('test', routing_key='test')
|
||||
|
||||
def callback(body, message):
|
||||
assert body == {'hello': 'world'}
|
||||
assert message.content_type == 'application/x-python-serialize'
|
||||
message.delivery_info['routing_key'] == 'test'
|
||||
message.delivery_info['exchange'] == ''
|
||||
message.ack()
|
||||
assert message.payload == body
|
||||
|
||||
with connection as conn:
|
||||
with conn.channel() as channel:
|
||||
producer = kombu.Producer(channel)
|
||||
producer.publish(
|
||||
{'hello': 'world'},
|
||||
retry=True,
|
||||
exchange=test_queue.exchange,
|
||||
routing_key=test_queue.routing_key,
|
||||
declare=[test_queue],
|
||||
serializer='pickle'
|
||||
)
|
||||
|
||||
consumer = kombu.Consumer(conn, [test_queue], accept=['pickle'])
|
||||
consumer.register_callback(callback)
|
||||
with consumer:
|
||||
conn.drain_events(timeout=1)
|
||||
|
||||
|
||||
@pytest.mark.env('redis')
|
||||
@pytest.mark.flaky(reruns=5, reruns_delay=2)
|
||||
def test_simple_publish_consume(connection):
|
||||
with connection as conn:
|
||||
with closing(conn.SimpleQueue('simple_test')) as queue:
|
||||
queue.put({'Hello': 'World'}, headers={'k1': 'v1'})
|
||||
message = queue.get(timeout=1)
|
||||
assert message.payload == {'Hello': 'World'}
|
||||
assert message.content_type == 'application/json'
|
||||
assert message.content_encoding == 'utf-8'
|
||||
assert message.headers == {'k1': 'v1'}
|
||||
message.ack()
|
11
tox.ini
11
tox.ini
|
@ -2,6 +2,7 @@
|
|||
envlist =
|
||||
{2.7,pypy,pypy3,3.5,3.6,3.7-{linux,windows},3.8{linux,windows}}-unit
|
||||
{2.7,pypy,pypy3,3.5,3.6,3.7-{linux,windows},3.8{linux,windows}}-integration-py-amqp
|
||||
{2.7,pypy,pypy3,3.5,3.6,3.7-{linux,windows},3.8{linux,windows}}-integration-redis
|
||||
flake8
|
||||
flakeplus
|
||||
apicheck
|
||||
|
@ -27,6 +28,7 @@ deps=
|
|||
commands =
|
||||
unit: python -bb -m pytest -rxs -xv --cov=kombu --cov-report=xml --no-cov-on-fail {posargs}
|
||||
integration-py-amqp: py.test -xv -E py-amqp t/integration {posargs:-n2}
|
||||
integration-redis: py.test -xv -E redis t/integration {posargs:-n2}
|
||||
|
||||
basepython =
|
||||
2.7,flakeplus,flake8,linkcheck,cov: python2.7
|
||||
|
@ -40,6 +42,7 @@ install_command = python -m pip --disable-pip-version-check install {opts} {pack
|
|||
|
||||
docker =
|
||||
integration-py-amqp: rabbitmq:alpine
|
||||
integration-redis: redis:alpine
|
||||
|
||||
dockerenv =
|
||||
PYAMQP_INTEGRATION_INSTANCE=1
|
||||
|
@ -53,6 +56,14 @@ healthcheck_timeout = 10
|
|||
healthcheck_retries = 30
|
||||
healthcheck_start_period = 5
|
||||
|
||||
[docker:redis:alpine]
|
||||
ports = 6379:6379/tcp
|
||||
healthcheck_cmd = /bin/sh -c 'redis-cli ping'
|
||||
healthcheck_interval = 10
|
||||
healthcheck_timeout = 10
|
||||
healthcheck_retries = 30
|
||||
healthcheck_start_period = 5
|
||||
|
||||
[testenv:apicheck]
|
||||
commands = pip install -U -r{toxinidir}/requirements/dev.txt
|
||||
sphinx-build -j2 -b apicheck -d {envtmpdir}/doctrees docs docs/_build/apicheck
|
||||
|
|
Loading…
Reference in New Issue