diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-04-09 22:41:33 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-04-09 22:50:21 +0200 |
| commit | f6f188ffc7d48f7f38edea35234f23f2cfefda0b (patch) | |
| tree | aab9c7f0c717becddb28cc42d8112f2e70eec95f /tests/backends | |
| parent | 396d65b5807cc6e25e2559634bdc8d6cfc22a837 (diff) | |
[1.7.x] Fixed #21553 -- Ensured unusable database connections get closed.
Backport of 5f2f47f from master
Diffstat (limited to 'tests/backends')
| -rw-r--r-- | tests/backends/tests.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index eaded5dbae..e6a557ba6b 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -664,6 +664,37 @@ class BackendTestCase(TestCase): self.assertTrue(cursor.closed) +class IsUsableTests(TransactionTestCase): + # Avoid using a regular TestCase because Django really dislikes closing + # the database connection inside a transaction at this point (#21202). + + available_apps = [] + + # Unfortunately with sqlite3 the in-memory test database cannot be closed. + @skipUnlessDBFeature('test_db_allows_multiple_connections') + def test_is_usable_after_database_disconnects(self): + """ + Test that is_usable() doesn't crash when the database disconnects. + + Regression for #21553. + """ + # Open a connection to the database. + with connection.cursor(): + pass + # Emulate a connection close by the database. + connection._close() + # Even then is_usable() should not raise an exception. + try: + self.assertFalse(connection.is_usable()) + finally: + # Clean up the mess created by connection._close(). Since the + # connection is already closed, this crashes on some backends. + try: + connection.close() + except Exception: + pass + + # We don't make these tests conditional because that means we would need to # check and differentiate between: # * MySQL+InnoDB, MySQL+MYISAM (something we currently can't do). |
