@@ -39,36 +39,44 @@ def live_server_url(self):
3939 def live_server_ws_url (self ):
4040 return "ws://%s:%s" % (self .host , self ._port )
4141
42- def _pre_setup (self ):
42+ @classmethod
43+ def setUpClass (cls ):
4344 for connection in connections .all ():
44- if self ._is_in_memory_db (connection ):
45+ if cls ._is_in_memory_db (connection ):
4546 raise ImproperlyConfigured (
4647 "ChannelLiveServerTestCase can not be used with in memory databases"
4748 )
4849
49- super (ChannelsLiveServerTestCase , self ). _pre_setup ()
50+ super (). setUpClass ()
5051
51- self ._live_server_modified_settings = modify_settings (
52- ALLOWED_HOSTS = {"append" : self .host }
52+ cls ._live_server_modified_settings = modify_settings (
53+ ALLOWED_HOSTS = {"append" : cls .host }
5354 )
54- self ._live_server_modified_settings .enable ()
55+ cls ._live_server_modified_settings .enable ()
5556
5657 get_application = partial (
5758 make_application ,
58- static_wrapper = self .static_wrapper if self .serve_static else None ,
59+ static_wrapper = cls .static_wrapper if cls .serve_static else None ,
5960 )
60- self ._server_process = self .ProtocolServerProcess (self .host , get_application )
61- self ._server_process .start ()
62- self ._server_process .ready .wait ()
63- self ._port = self ._server_process .port .value
61+ cls ._server_process = cls .ProtocolServerProcess (cls .host , get_application )
62+ cls ._server_process .start ()
63+ while True :
64+ if not cls ._server_process .ready .wait (timeout = 1 ):
65+ if cls ._server_process .is_alive ():
66+ continue
67+ raise RuntimeError ("Server stopped" ) from None
68+ break
69+ cls ._port = cls ._server_process .port .value
6470
65- def _post_teardown (self ):
66- self ._server_process .terminate ()
67- self ._server_process .join ()
68- self ._live_server_modified_settings .disable ()
69- super (ChannelsLiveServerTestCase , self )._post_teardown ()
71+ @classmethod
72+ def tearDownClass (cls ):
73+ cls ._server_process .terminate ()
74+ cls ._server_process .join ()
75+ cls ._live_server_modified_settings .disable ()
76+ super ().tearDownClass ()
7077
71- def _is_in_memory_db (self , connection ):
78+ @classmethod
79+ def _is_in_memory_db (cls , connection ):
7280 """
7381 Check if DatabaseWrapper holds in memory database.
7482 """
0 commit comments