Bläddra i källkod

Use Django DB max age connection setting (fixes #4116) (#4292)

Marco Schweighauser 7 år sedan
förälder
incheckning
c086cfd27b
2 ändrade filer med 6 tillägg och 5 borttagningar
  1. 1 1
      celery/fixups/django.py
  2. 5 4
      t/unit/fixups/test_django.py

+ 1 - 1
celery/fixups/django.py

@@ -183,7 +183,7 @@ class DjangoWorkerFixup(object):
     def _close_database(self):
         for conn in self._db.connections.all():
             try:
-                conn.close()
+                conn.close_if_unusable_or_obsolete()
             except self.interface_errors:
                 pass
             except self.DatabaseError as exc:

+ 5 - 4
t/unit/fixups/test_django.py

@@ -216,11 +216,12 @@ class test_DjangoWorkerFixup(FixupCase):
             f._db.connections.all.side_effect = lambda: conns
 
             f._close_database()
-            conns[0].close.assert_called_with()
-            conns[1].close.assert_called_with()
-            conns[2].close.assert_called_with()
+            conns[0].close_if_unusable_or_obsolete.assert_called_with()
+            conns[1].close_if_unusable_or_obsolete.assert_called_with()
+            conns[2].close_if_unusable_or_obsolete.assert_called_with()
 
-            conns[1].close.side_effect = KeyError('omg')
+            conns[1].close_if_unusable_or_obsolete.side_effect = KeyError(
+                'omg')
             with pytest.raises(KeyError):
                 f._close_database()