-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c7aae9
commit a06816b
Showing
24 changed files
with
549 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
services: | ||
|
||
redis: | ||
image: redis:latest | ||
container_name: redis-primary | ||
command: redis-server --enable-debug-command yes --protected-mode no | ||
ports: | ||
- 6379:6379 | ||
healthcheck: | ||
test: redis-cli ping | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
sentinel: | ||
image: redis:latest | ||
container_name: redis-sentinel | ||
depends_on: | ||
redis: | ||
condition: service_healthy | ||
entrypoint: "redis-sentinel /redis.conf --port 26379" | ||
ports: | ||
- 26379:26379 | ||
volumes: | ||
- "./sentinel.conf:/redis.conf" | ||
healthcheck: | ||
test: redis-cli -p 26379 ping | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sentinel monitor default_service 127.0.0.1 6379 1 | ||
sentinel down-after-milliseconds default_service 3200 | ||
sentinel failover-timeout default_service 10000 | ||
sentinel parallel-syncs default_service 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
from os import environ | ||
from typing import Iterable | ||
|
||
import pytest | ||
from django.core.cache import cache as default_cache | ||
from pytest import Metafunc | ||
from xdist.scheduler import LoadScopeScheduling | ||
|
||
from django_redis.cache import BaseCache | ||
from tests.settings_wrapper import SettingsWrapper | ||
|
||
|
||
class FixtureScheduling(LoadScopeScheduling): | ||
"""Split by [] value. This is very hackish and might blow up any time!""" | ||
|
||
def _split_scope(self, nodeid): | ||
if "[sqlite" in nodeid: | ||
return nodeid.rsplit("[")[-1].replace("]", "") | ||
return None | ||
|
||
|
||
def pytest_xdist_make_scheduler(log, config): | ||
return FixtureScheduling(config, log) | ||
|
||
|
||
@pytest.fixture() | ||
def settings(): | ||
"""A Django settings object which restores changes after the testrun""" | ||
wrapper = SettingsWrapper() | ||
yield wrapper | ||
wrapper.finalize() | ||
|
||
|
||
@pytest.fixture | ||
def cache() -> Iterable[BaseCache]: | ||
def cache(cache_settings: str) -> Iterable[BaseCache]: | ||
from django import setup | ||
|
||
environ["DJANGO_SETTINGS_MODULE"] = f"settings.{cache_settings}" | ||
setup() | ||
|
||
from django.core.cache import cache as default_cache | ||
|
||
yield default_cache | ||
default_cache.clear() | ||
|
||
|
||
def pytest_generate_tests(metafunc: Metafunc): | ||
if "cache" in metafunc.fixturenames or "session" in metafunc.fixturenames: | ||
# Mark | ||
settings = [ | ||
"sqlite", | ||
"sqlite_gzip", | ||
"sqlite_herd", | ||
"sqlite_json", | ||
"sqlite_lz4", | ||
"sqlite_msgpack", | ||
"sqlite_sentinel", | ||
"sqlite_sentinel_opts", | ||
"sqlite_sharding", | ||
"sqlite_usock", | ||
"sqlite_zlib", | ||
"sqlite_zstd", | ||
] | ||
metafunc.parametrize("cache_settings", settings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.