Skip to content

Commit

Permalink
tests: fix spurious failure of stats tests
Browse files Browse the repository at this point in the history
Some of the test_stats tests would fail occasionally with the wrong
queue length.  Traced it back to the redis 'Queue' object somehow
persisting across tests.  We now ensure that a fresh queue is used
for each test.

Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
  • Loading branch information
efahl committed Oct 23, 2024
1 parent 060ec53 commit de15c77
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from fakeredis import FakeStrictRedis
from rq import Queue
from fastapi.testclient import TestClient

from asu.config import settings
Expand Down Expand Up @@ -93,12 +94,16 @@ def app(redis_server, test_path, monkeypatch):
def mocked_redis_client(*args, **kwargs):
return redis_server

def mocked_redis_queue():
return Queue(connection=redis_server, is_async=settings.async_queue)

settings.public_path = Path(test_path) / "public"
settings.async_queue = False
for branch in "1.2", "19.07", "21.02":
if branch not in settings.branches:
settings.branches[branch] = {"path": "releases/{version}"}

monkeypatch.setattr("asu.util.get_queue", mocked_redis_queue)
monkeypatch.setattr("asu.util.get_redis_client", mocked_redis_client)
monkeypatch.setattr("asu.routers.api.get_redis_client", mocked_redis_client)

Expand Down

0 comments on commit de15c77

Please sign in to comment.