@@ -53,7 +53,7 @@ def send(self, data):
5353
5454
5555class Test_WSSessionManager__execute (TestCase ):
56- """ It's very hard to make this test fail but it will catch major regressions
56+ """ It's very hard to make this test fail, but it will catch major regressions
5757 """
5858 def setUp (self ):
5959 self .pool = ThreadPool (10 )
@@ -84,7 +84,7 @@ def _send(message):
8484
8585
8686class Test_WSSessionManager_get_events (TestCase ):
87- """ It's very hard to make this test fail but it will catch major regressions
87+ """ It's very hard to make this test fail, but it will catch major regressions
8888 """
8989
9090 def test_locked_get_events (self ):
@@ -188,11 +188,36 @@ def close(self):
188188 pass
189189
190190
191+ class Test_WSSessionManager_blocked_with_domains (TestCase ):
192+ """ We need this test to prove we have fixed the problem of a message producer being blocked.
193+ When it tried to recreate the websocket, it shouldn't deadlock.
194+ """
195+
196+ def tearDown (self ):
197+ self .session_manager .close ()
198+
199+ def test_deadlock (self ):
200+
201+ with patch .object (
202+ _WSMessageProducer , "_get_websocket" ,
203+ new = MagicMock (return_value = _DummyWebsocket ())
204+ ):
205+
206+ self .session_manager = WSSessionManager (
207+ 1234 , "localhost" , 2 , domains = {"Network" : {}}
208+ )
209+ # The first message producer and web socket are clocked.
210+ # When the ws session is recreated we get a new one which won't be blocked.
211+ self .session_manager ._message_producer ._BLOCKED_TIMEOUT = - 1
212+
213+ self .session_manager .execute ("Network" , "enable" )
214+
215+
191216class Test_WSSessionManager_execute (TestCase ):
192217
193218 @staticmethod
194219 def resetWS ():
195- """ flush_messages runs async so we only want the socket to start blocking when we're
220+ """ flush_messages runs async, so we only want the socket to start blocking when we're
196221 ready
197222 """
198223 ExceptionThrowingWS .exceptions = 0
@@ -218,6 +243,7 @@ def test_thread_blocked_once(self):
218243 start = time .time ()
219244 self .session_manager .execute ("Network" , "enable" )
220245
246+ # todo wtf
221247 # We should find the execution result after 5 seconds because
222248 # we give the thread 5 seconds to poll before we consider it blocked,
223249 self .assertLess (time .time () - start , 10 )
@@ -241,8 +267,8 @@ def test_thread_blocks_causes_timeout(self):
241267
242268 self .session_manager = WSSessionManager (1234 , "localhost" , 3 )
243269 self .resetWS ()
270+ start = time .time ()
244271 with self .assertRaises (DevToolsTimeoutException ):
245- start = time .time ()
246272 self .session_manager .execute ("Network" , "enable" )
247273 self .assertLess (time .time () - start , 5 )
248274
0 commit comments