...
 
Commits (3)
......@@ -245,14 +245,14 @@ def setting(*names):
@cli2.command(color=cli2.GREEN)
@cli2.option('quiet', alias='q', help='Silence all output.')
@cli2.option('debug', alias='d', help='Display debug output (overrides -q).')
def checkdb(sleep_for=1.0, max_tries=10):
def dbcheck(sleep_for=1.0, max_tries=10):
"""Check all database connections.
Verify that all the databases are ready (e.g. before attempting to start
Django dev server).
:param float sleep: Seconds to sleep between attempts.
:param int repeat: Number of attempts to retry before failing.
:param float sleep_for: Seconds to sleep between attempts.
:param int max_tries: Number of attempts to retry before failing.
"""
from django.db import connections
from django.db.utils import OperationalError
......@@ -266,7 +266,7 @@ def checkdb(sleep_for=1.0, max_tries=10):
if debug:
print(
f'Checkdb parameters: sleep_for={sleep_for}; max_tries={max_tries}'
f'dbcheck parameters: sleep_for={sleep_for}; max_tries={max_tries}'
)
for conn in connections:
......
......@@ -18,8 +18,8 @@ import cli2
('ls_empty', 'ls auth.user username first_name'),
('chpasswd_empty', 'chpasswd username=fail'),
('delete_empty', 'delete auth.user username'),
('checkdb_available', 'checkdb'),
('checkdb_available_debug', 'checkdb --debug'),
('dbcheck_available', 'dbcheck'),
('dbcheck_available_debug', 'dbcheck --debug'),
])
@pytest.mark.django_db
def test_djcli_empty(name, command):
......@@ -27,11 +27,11 @@ def test_djcli_empty(name, command):
@pytest.mark.parametrize('name,command', [
('checkdb_missing', 'checkdb sleep_for=0.1 max_tries=5'),
('checkdb_missing_debug', 'checkdb sleep_for=0.1 max_tries=5 --debug'),
('dbcheck_missing', 'dbcheck sleep_for=0.1 max_tries=5'),
('dbcheck_missing_debug', 'dbcheck sleep_for=0.1 max_tries=5 --debug'),
])
@pytest.mark.django_db
def test_checkdb_missing(name, command, settings):
def test_dbcheck_missing(name, command, settings):
"""Override settings to simulate a missing database.
Add a new database to avoid conflict with the test runner in-memory db.
......
command: djcli checkdb --debug
retcode: 1
stdout:
Checkdb parameters: sleep_for=1.0; max_tries=10
command: djcli checkdb
command: djcli dbcheck
retcode: 1
stdout:
command: djcli dbcheck --debug
retcode: 1
stdout:
dbcheck parameters: sleep_for=1.0; max_tries=10
command: djcli checkdb sleep_for=0.1 max_tries=5
command: djcli dbcheck sleep_for=0.1 max_tries=5
retcode: 1
stdout:
Attempting to connect to database fake_sqlite3 returns an error:
......
command: djcli checkdb sleep_for=0.1 max_tries=5 --debug
command: djcli dbcheck sleep_for=0.1 max_tries=5 --debug
retcode: 1
stdout:
Checkdb parameters: sleep_for=0.1; max_tries=5
dbcheck parameters: sleep_for=0.1; max_tries=5
Waiting 0.1 second(s) for database fake_sqlite3...
Waiting 0.1 second(s) for database fake_sqlite3...
Waiting 0.1 second(s) for database fake_sqlite3...
......