-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #757 from WisdomPill/parallel_tests
- Loading branch information
Showing
25 changed files
with
577 additions
and
546 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,4 @@ | ||
Speed up tests by using `pytest-xdist` and separating settings on different redis databases. | ||
Dropped `pytest-django` | ||
Using `docker-compose` for setting up redis containers for testing | ||
Use `tox-uv` |
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,68 @@ | ||
import sys | ||
from os import environ | ||
from pathlib import Path | ||
from typing import Iterable | ||
|
||
import pytest | ||
from django.core.cache import cache as default_cache | ||
from xdist.scheduler import LoadScopeScheduling | ||
|
||
from django_redis.cache import BaseCache | ||
from tests.settings_wrapper import SettingsWrapper | ||
|
||
|
||
@pytest.fixture | ||
def cache() -> Iterable[BaseCache]: | ||
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) | ||
|
||
|
||
def pytest_configure(config): | ||
sys.path.insert(0, str(Path(__file__).absolute().parent)) | ||
|
||
|
||
@pytest.fixture() | ||
def settings(): | ||
"""A Django settings object which restores changes after the testrun""" | ||
wrapper = SettingsWrapper() | ||
yield wrapper | ||
wrapper.finalize() | ||
|
||
|
||
@pytest.fixture() | ||
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): | ||
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
Oops, something went wrong.