@@ -119,8 +119,10 @@ def test_successful_download(self, mock_requests, mock_load, mock_open, mock_mak
119119
120120
121121class TestWaitForStatus (SetUpGraphModule ):
122+ @patch ("centml.compiler.config.settings.COMPILING_SLEEP_TIME" , new = 0 )
122123 @patch ("centml.compiler.backend.requests" )
123- def test_invalid_status (self , mock_requests ):
124+ @patch ("logging.Logger.exception" )
125+ def test_invalid_status (self , mock_logger , mock_requests ):
124126 mock_response = MagicMock ()
125127 mock_response .status_code = HTTPStatus .BAD_REQUEST
126128 mock_requests .get .return_value = mock_response
@@ -129,8 +131,28 @@ def test_invalid_status(self, mock_requests):
129131 with self .assertRaises (Exception ) as context :
130132 self .runner ._wait_for_status (model_id )
131133
132- mock_requests .get .assert_called_once ()
133- self .assertIn ("Status check: request failed, exception from server" , str (context .exception ))
134+ mock_requests .get .assert_called ()
135+ assert mock_requests .get .call_count == settings .MAX_RETRIES + 1
136+ assert len (mock_logger .call_args_list ) == settings .MAX_RETRIES + 1
137+ print (mock_logger .call_args_list )
138+ assert mock_logger .call_args_list [0 ].startswith ("Status check failed:" )
139+ assert "Waiting for status: compilation failed too many times.\n " == str (context .exception )
140+
141+ @patch ("centml.compiler.config.settings.COMPILING_SLEEP_TIME" , new = 0 )
142+ @patch ("centml.compiler.backend.requests" )
143+ @patch ("logging.Logger.exception" )
144+ def test_exception_in_status (self , mock_logger , mock_requests ):
145+ exception_message = "Exiting early"
146+ mock_requests .get .side_effect = Exception (exception_message )
147+
148+ model_id = "exception_in_status"
149+ with self .assertRaises (Exception ) as context :
150+ self .runner ._wait_for_status (model_id )
151+
152+ mock_requests .get .assert_called ()
153+ assert mock_requests .get .call_count == settings .MAX_RETRIES + 1
154+ mock_logger .assert_called_with (f"Status check failed:\n { exception_message } " )
155+ assert str (context .exception ) == "Waiting for status: compilation failed too many times.\n "
134156
135157 @patch ("centml.compiler.config.settings.COMPILING_SLEEP_TIME" , new = 0 )
136158 @patch ("centml.compiler.backend.Runner._compile_model" )
@@ -151,6 +173,7 @@ def test_max_tries(self, mock_requests, mock_compile):
151173 @patch ("centml.compiler.config.settings.COMPILING_SLEEP_TIME" , new = 0 )
152174 @patch ("centml.compiler.backend.requests" )
153175 def test_wait_on_compilation (self , mock_requests ):
176+ # Mock the status check
154177 COMPILATION_STEPS = 10
155178 mock_response = MagicMock ()
156179 mock_response .status_code = HTTPStatus .OK
@@ -163,6 +186,34 @@ def test_wait_on_compilation(self, mock_requests):
163186 # _wait_for_status should return True when compilation DONE
164187 assert self .runner ._wait_for_status (model_id )
165188
189+ @patch ("centml.compiler.config.settings.COMPILING_SLEEP_TIME" , new = 0 )
190+ @patch ("centml.compiler.backend.requests" )
191+ @patch ("centml.compiler.backend.Runner._compile_model" )
192+ @patch ("logging.Logger.exception" )
193+ def test_exception_in_compilation (self , mock_logger , mock_compile , mock_requests ):
194+ # Mock the status check
195+ mock_response = MagicMock ()
196+ mock_response .status_code = HTTPStatus .OK
197+ mock_response .json .return_value = {"status" : CompilationStatus .NOT_FOUND .value }
198+ mock_requests .get .return_value = mock_response
199+
200+ # Mock the compile model function
201+ exception_message = "Exiting early"
202+ mock_compile .side_effect = Exception (exception_message )
203+
204+ model_id = "exception_in_compilation"
205+ with self .assertRaises (Exception ) as context :
206+ self .runner ._wait_for_status (model_id )
207+
208+ mock_requests .get .assert_called ()
209+ assert mock_requests .get .call_count == settings .MAX_RETRIES + 1
210+
211+ mock_compile .assert_called ()
212+ assert mock_compile .call_count == settings .MAX_RETRIES + 1
213+
214+ mock_logger .assert_called_with (f"Submitting compilation failed:\n { exception_message } " )
215+ assert str (context .exception ) == "Waiting for status: compilation failed too many times.\n "
216+
166217 @patch ("centml.compiler.backend.requests" )
167218 def test_compilation_done (self , mock_requests ):
168219 mock_response = MagicMock ()
0 commit comments