Skip to content

Commit cd8bcc8

Browse files
committed
Fix coverage
1 parent c4d1583 commit cd8bcc8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/unit/common/core/test_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,33 @@ def test_using_database_replica__sequential__falls_back_to_cross_region_replica(
386386
using_database_replica(manager).first()
387387
with django_assert_num_queries(1, using="cross_region_replica_1"):
388388
using_database_replica(manager).first()
389+
390+
391+
@pytest.mark.django_db(databases="__all__")
392+
@pytest.mark.parametrize("strategy", ["distributed", "sequential"])
393+
def test_using_database_replica__sequential__raises_if_all_replicas_unavailable(
394+
bad_replica: MockType,
395+
mocker: MockerFixture,
396+
settings: SettingsWrapper,
397+
strategy: str,
398+
) -> None:
399+
# Given
400+
settings.REPLICA_READ_STRATEGY = strategy
401+
manager = get_user_model().objects
402+
bad_replica = mocker.Mock()
403+
bad_replica.ensure_connection.side_effect = OperationalError("Connection failed")
404+
mocker.patch(
405+
"common.core.utils.connections",
406+
{
407+
"default": connections["default"],
408+
"replica_1": bad_replica,
409+
"replica_2": bad_replica,
410+
"replica_3": bad_replica,
411+
"cross_region_replica_1": bad_replica,
412+
"cross_region_replica_2": bad_replica,
413+
},
414+
)
415+
416+
# When / Then
417+
with pytest.raises(OperationalError):
418+
using_database_replica(manager).first()

0 commit comments

Comments
 (0)