diff --git a/sprockets_postgres.py b/sprockets_postgres.py index 783ba73..4bec921 100644 --- a/sprockets_postgres.py +++ b/sprockets_postgres.py @@ -408,7 +408,8 @@ class ApplicationMixin: } """ - if not self._postgres_connected.is_set(): + if not self._postgres_connected or \ + not self._postgres_connected.is_set(): return { 'available': False, 'pool_size': 0, diff --git a/tests.py b/tests.py index ea1a2c9..ee2bfd4 100644 --- a/tests.py +++ b/tests.py @@ -349,6 +349,18 @@ class TestCase(testing.SprocketsHttpTestCase): return self.app +class PostgresStatusTestCase(asynctest.TestCase): + + async def test_postgres_status_before_first_connection(self): + app = Application() + status = await app.postgres_status() + self.assertEqual( + status, + {'available': False, + 'pool_size': 0, + 'pool_free': 0}) + + class RequestHandlerMixinTestCase(TestCase): def test_postgres_status(self):