Skip to content

Commit

Permalink
Update unit tests for async
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Jul 21, 2023
1 parent b1bbc1d commit 8d5dd60
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 110 deletions.
2 changes: 1 addition & 1 deletion api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pook = "~=1.0"
pgcli = "~=3.5"
freezegun = "~=1.2.2"
pytest-sugar = "~=0.9"
pytest-asyncio = "~=0.21.1"

[packages]
aiohttp = "~=3.8"
Expand Down Expand Up @@ -51,7 +52,6 @@ requests-oauthlib = "~=1.3"
sentry-sdk = "~=1.21"
django-split-settings = "*"
adrf = "*"
django-async-redis = "*"
uvicorn = "*"
gunicorn = "~=20.1"

Expand Down
61 changes: 33 additions & 28 deletions api/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions api/conf/settings/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,27 @@
REDIS_PASSWORD = config("REDIS_PASSWORD", default="")


def _make_cache_config(dbnum: int, aio: bool = False, **overrides) -> dict:
library = "django_async_redis" if aio else "django_redis"
def _make_cache_config(dbnum: int, **overrides) -> dict:
return {
"BACKEND": f"{library}.cache.RedisCache",
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/{dbnum}",
"OPTIONS": {
"CLIENT_CLASS": f"{library}.client.DefaultClient",
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
| overrides.pop("OPTIONS", {}),
} | overrides


# `a` prefixed caches use aioredis backend
CACHES = {
# Site cache writes to 'default'
"default": _make_cache_config(0),
"adefault": _make_cache_config(0, aio=True),
# For rapidly changing stats that we don't want to hammer the database with
"traffic_stats": _make_cache_config(1),
"atraffic_stats": _make_cache_config(1, aio=True),
# For ensuring consistency among multiple Django workers and servers.
# Used by Redlock.
"locks": _make_cache_config(2),
"alocks": _make_cache_config(2, aio=True),
# Used for tracking tallied figures that shouldn't expire and are indexed
# with a timestamp range (for example, the key could a timestamp valid
# for a given week), allowing historical data analysis.
"tallies": _make_cache_config(3, TIMEOUT=None),
"atallies": _make_cache_config(3, aio=True, TIMEOUT=None),
}
3 changes: 3 additions & 0 deletions api/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[pytest]
DJANGO_SETTINGS_MODULE = conf.settings

# https://pytest-asyncio.readthedocs.io/en/latest/concepts.html#auto-mode
asyncio_mode = auto

pythonpath = .

filterwarnings=
Expand Down
Loading

0 comments on commit 8d5dd60

Please sign in to comment.