Skip to content

Commit

Permalink
Set up redis on GitHub Actions
Browse files Browse the repository at this point in the history
I've set up the environment variables for general CI usage, even though
in this case the defaults work.
  • Loading branch information
RazerM committed Jun 16, 2023
1 parent b835890 commit bc6c56a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ jobs:
name: "Python ${{ matrix.python-version }}"
runs-on: "ubuntu-latest"

services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
Expand Down
9 changes: 6 additions & 3 deletions tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import pytest

REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', '6379'))


@require_module('zmq')
def test_zeromq_handler(logger, handlers, subscriber):
Expand Down Expand Up @@ -225,7 +228,7 @@ def test_redis_handler():

KEY = 'redis-{}'.format(os.getpid())
FIELDS = ['message', 'host']
r = redis.Redis(decode_responses=True)
r = redis.Redis(REDIS_HOST, REDIS_PORT, decode_responses=True)
redis_handler = RedisHandler(key=KEY, level=logbook.INFO, bubble=True)
# We don't want output for the tests, so we can wrap everything in a
# NullHandler
Expand Down Expand Up @@ -304,7 +307,7 @@ def test_redis_handler_lpush():

time.sleep(1.5)

r = redis.Redis(decode_responses=True)
r = redis.Redis(REDIS_HOST, REDIS_PORT, decode_responses=True)
logs = r.lrange(KEY, 0, -1)
assert logs
assert "new item" in logs[0]
Expand Down Expand Up @@ -332,7 +335,7 @@ def test_redis_handler_rpush():

time.sleep(1.5)

r = redis.Redis(decode_responses=True)
r = redis.Redis(REDIS_HOST, REDIS_PORT, decode_responses=True)
logs = r.lrange(KEY, 0, -1)
assert logs
assert "old item" in logs[0]
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ extras =
test
set_env =
nospeedups: DISABLE_LOGBOOK_CEXT_AT_RUNTIME=1
pass_env =
REDIS_HOST
REDIS_PORT
commands =
pytest {posargs}

Expand Down

0 comments on commit bc6c56a

Please sign in to comment.