Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency safety #571

Closed
0x2b3bfa0 opened this issue Nov 15, 2023 · 1 comment
Closed

Concurrency safety #571

0x2b3bfa0 opened this issue Nov 15, 2023 · 1 comment

Comments

@0x2b3bfa0
Copy link

0x2b3bfa0 commented Nov 15, 2023

The redisdb fixture runs FLUSHALL after every single test, indiscriminately deleting all the data stored on Redis.

When using an existing Redis instance for all the tests (i.e. with the redis_noproc fixture) and running tests in parallel with pytest-xdist, some tests will fail at random, because all the data is flushed amidst their execution.

yield redis_client
redis_client.flushall()

What action do you want to perform

$ pytest --numprocesses=2 test.py
import time

from pytest_redis.factories import redis_noproc, redisdb


redis_noproc = redis_noproc()
redis = redisdb("redis_noproc")


def test_one(redis):
    ...


def test_two(redis):
    redis.set("key", b"value")
    time.sleep(1)  # In the meantime, test_one will run, triggering a FLUSHALL.
    assert redis.get("key") == b"value"

What are the results

The test_two will fail, because the test_one will trigger a FLUSHALL as soon as it returns.

What are the expected results

Both tests should succeed.

@0x2b3bfa0
Copy link
Author

0x2b3bfa0 commented Nov 16, 2023

pytest-dev/pytest-xdist#385 (comment)

The easiest workaround for our use case was using pytest --dist=loadgroup to run all the tests relying on the redis fixture serially:

import pytest
import redis


@pytest.mark.xdist_group(name="redis")
def test_one(redis: redis.Redis):
    ...


@pytest.mark.xdist_group(name="redis")
def test_two(redis: redis.Redis):
    ...

@0x2b3bfa0 0x2b3bfa0 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant