diff --git a/django/test/testcases.py b/django/test/testcases.py
index 53ea93f..fb8ac52 100644
|
a
|
b
|
class LiveServerThread(threading.Thread):
|
| 1116 | 1116 | self.httpd.set_app(handler) |
| 1117 | 1117 | self.is_ready.set() |
| 1118 | 1118 | self.httpd.serve_forever() |
| | 1119 | for alias in connections: |
| | 1120 | connections[alias].close() |
| 1119 | 1121 | except Exception as e: |
| 1120 | 1122 | self.error = e |
| 1121 | 1123 | self.is_ready.set() |
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index 2331a0d..2012f3c 100644
|
a
|
b
|
class LiveServerDatabase(LiveServerBase):
|
| 185 | 185 | ['jane', 'robert', 'emily'], |
| 186 | 186 | lambda b: b.name |
| 187 | 187 | ) |
| | 188 | |
| | 189 | |
| | 190 | class LiveServerPersistentDatabase(LiveServerBase): |
| | 191 | |
| | 192 | def test_connection_closing(self): |
| | 193 | self.connection_closed = False |
| | 194 | |
| | 195 | from django.db import connections, DEFAULT_DB_ALIAS |
| | 196 | connection = connections[DEFAULT_DB_ALIAS] |
| | 197 | |
| | 198 | # Mark connection as persistent |
| | 199 | connection.close_at = None |
| | 200 | |
| | 201 | # Monkey-patch to check when is it closed |
| | 202 | original_close = connection.close |
| | 203 | def wrapped_close(): |
| | 204 | self.connection_closed = True |
| | 205 | return original_close() |
| | 206 | connection.close = wrapped_close |
| | 207 | |
| | 208 | # Force the LiveServerThread to open a connection |
| | 209 | self.urlopen('/example_view/') |
| | 210 | |
| | 211 | # Stop the server |
| | 212 | self.server_thread.terminate() |
| | 213 | self.server_thread.join() |
| | 214 | |
| | 215 | # The connection must have been closed by the server |
| | 216 | self.assertTrue(self.connection_closed) |