diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-06-29 18:26:48 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook.git@proton.me> | 2022-07-05 19:02:01 -0500 |
commit | 229f61225e0cde4be64242e713ae34b80572afb8 (patch) | |
tree | 8254103c0385cabff0de54597bdb0f00bae34068 /tests | |
parent | f5bf4716f4d184b92c72a06619461ebea78817ac (diff) | |
download | requests-cache-229f61225e0cde4be64242e713ae34b80572afb8.tar.gz |
Add retries for MongoDB ServerSelectionTimeoutError on GitHub Actions runners
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/test_mongodb.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/integration/test_mongodb.py b/tests/integration/test_mongodb.py index 856c0f4..fb56820 100644 --- a/tests/integration/test_mongodb.py +++ b/tests/integration/test_mongodb.py @@ -1,15 +1,22 @@ +from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor from logging import getLogger from time import sleep from unittest.mock import patch import pytest +from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed from requests_cache.backends import GridFSCache, GridFSDict, MongoCache, MongoDict from requests_cache.policy import NEVER_EXPIRE -from tests.conftest import fail_if_no_connection, httpbin +from tests.conftest import N_ITERATIONS, fail_if_no_connection, httpbin from tests.integration.base_cache_test import BaseCacheTest from tests.integration.base_storage_test import BaseStorageTest +try: + from pymongo.errors import ServerSelectionTimeoutError +except ImportError: + pass + logger = getLogger(__name__) @@ -84,6 +91,20 @@ class TestMongoCache(BaseCacheTest): session.cache.set_ttl(NEVER_EXPIRE, overwrite=True) assert session.cache.get_ttl() is None + @retry( + retry=retry_if_exception_type(ServerSelectionTimeoutError), + reraise=True, + stop=stop_after_attempt(5), + wait=wait_fixed(5), + ) + @pytest.mark.parametrize('executor_class', [ThreadPoolExecutor, ProcessPoolExecutor]) + @pytest.mark.parametrize('iteration', range(N_ITERATIONS)) + def test_concurrency(self, iteration, executor_class): + """On GitHub runners, sometimes the MongoDB container is not ready yet by the time this, + runs, so some retries are added here. + """ + super().test_concurrency(iteration, executor_class) + class TestGridFSDict(BaseStorageTest): storage_class = GridFSDict |