Code

Ticket #2879: 2879-error-fixes.diff

File 2879-error-fixes.diff, 1.5 KB (added by akaariai, 3 years ago)

Incremental to .10.diff

Line 
1diff --git a/django/test/testcases.py b/django/test/testcases.py
2index 30d6e98..5625b91 100644
3--- a/django/test/testcases.py
4+++ b/django/test/testcases.py
5@@ -778,6 +778,7 @@ class StoppableWSGIServer(WSGIServer):
6             r, w, e = select.select([self], [], [], poll_interval)
7             if r:
8                 self._handle_request_noblock()
9+        self.__serving = None
10         self.__is_shut_down.set()
11 
12     def shutdown(self):
13@@ -788,7 +789,10 @@ class StoppableWSGIServer(WSGIServer):
14         deadlock.
15         """
16         self.__serving = False
17-        self.__is_shut_down.wait()
18+        self.__is_shut_down.wait(2)
19+        if self.__serving is not None:
20+            raise RuntimeError("Failed to shutdown the server in 2 seconds. "
21+                               "The server might be stuck, or generating a slow response.")
22 
23     def handle_request(self):
24         """Handle one request, possibly blocking.
25@@ -865,6 +869,9 @@ class LiveServerThread(threading.Thread):
26         except WSGIServerException, e:
27             self.error = e
28             self.is_ready.set()
29+        except Exception, e:
30+            self.error = e
31+            self.is_ready.set()
32 
33     def join(self, timeout=None):
34         self.httpd.shutdown()
35@@ -904,6 +911,7 @@ class LiveServerTestCase(TransactionTestCase):
36             settings.LIVE_TEST_SERVER_HOST,
37             int(settings.LIVE_TEST_SERVER_PORT),
38             connections_override)
39+        cls.server_thread.daemon = True
40         cls.server_thread.start()
41 
42         # Wait for the Django server to be ready