mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-20 13:28:20 +02:00
Use custom db error when db init fails (#1720)
This commit is contained in:
parent
80cebd8514
commit
0b1f0a9257
2 changed files with 4 additions and 2 deletions
|
|
@ -49,6 +49,7 @@ from squeaknode.core.squeak_entry import SqueakEntry
|
|||
from squeaknode.core.squeak_peer import SqueakPeer
|
||||
from squeaknode.core.squeak_profile import SqueakProfile
|
||||
from squeaknode.core.squeaks import get_hash
|
||||
from squeaknode.db.exception import SqueakDatabaseError
|
||||
from squeaknode.db.migrations import run_migrations
|
||||
from squeaknode.db.models import Models
|
||||
|
||||
|
|
@ -96,7 +97,7 @@ class SqueakDb:
|
|||
logger.exception("Failed to initialize database.")
|
||||
n += 1
|
||||
if n >= num_retries:
|
||||
raise Exception("Failed to initialize database.")
|
||||
raise SqueakDatabaseError("Failed to initialize database.")
|
||||
time.sleep(retry_interval_s)
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import mock
|
|||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
from squeaknode.db.exception import SqueakDatabaseError
|
||||
from squeaknode.db.squeak_db import SqueakDb
|
||||
from tests.utils import gen_address
|
||||
from tests.utils import gen_contact_profile
|
||||
|
|
@ -423,7 +424,7 @@ def test_init_with_retries_fail_many_times(squeak_db):
|
|||
mock.patch('squeaknode.db.squeak_db.time.sleep', autospec=True) as mock_sleep:
|
||||
mock_init.side_effect = [Exception('some db error')] * 5
|
||||
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
with pytest.raises(SqueakDatabaseError) as excinfo:
|
||||
squeak_db.init_with_retries(num_retries=5, retry_interval_s=100)
|
||||
assert "Failed to initialize database." in str(excinfo.value)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue