@@ -122,6 +122,52 @@ def test_down_failure_or_timeout_stops_before_next_resource(self):
122122 hook .main ()
123123 self .assertEqual (self .run .call_count , 3 )
124124
125+ def test_abort_logs_bounded_status_diagnostics_without_down (self ):
126+ stderr = "discarded-prefix" + "x" * 2048 + "permission denied"
127+ self .run .return_value = subprocess .CompletedProcess ([], 12 , "" , stderr )
128+ with patch .object (hook , "connect_container_stdout" ):
129+ self .assertEqual (hook .run_hook (), 1 )
130+ self .assertEqual (self .run .call_count , 1 )
131+ self .assertEqual (self .run .call_args .kwargs ["errors" ], "replace" )
132+ self .events .assert_called_once_with (
133+ "abort-no-further-actions" , error_type = "RuntimeError" ,
134+ error = "status-command-failed (exit=12): " + stderr [- 2048 :],
135+ )
136+
137+ def test_abort_logs_down_diagnostics_and_stops_before_next_resource (self ):
138+ stderr = "discarded-prefix" + "x" * 2048 + "device busy"
139+ self .run .side_effect = [self .status (resource (), resource ("r2" )), self .status (resource ()),
140+ subprocess .CompletedProcess ([], 17 , stderr = stderr )]
141+ with patch .object (hook , "connect_container_stdout" ):
142+ self .assertEqual (hook .run_hook (), 1 )
143+ self .assertEqual (self .run .call_count , 3 )
144+ self .assertEqual (self .run .call_args .kwargs ["stderr" ], subprocess .PIPE )
145+ self .assertTrue (self .run .call_args .kwargs ["text" ])
146+ self .assertEqual (self .run .call_args .kwargs ["errors" ], "replace" )
147+ self .events .assert_called_with (
148+ "abort-no-further-actions" , error_type = "RuntimeError" ,
149+ error = "down-command-failed (exit=17): " + stderr [- 2048 :],
150+ )
151+
152+ def test_abort_logs_partial_timeout_stderr_for_status_and_down (self ):
153+ stderr = b"discarded-prefix" + b"x" * 2048 + b"device busy\xff "
154+ for command in ["status" , "down" ]:
155+ with self .subTest (command = command ):
156+ self .run .reset_mock ()
157+ self .events .reset_mock ()
158+ failure = subprocess .TimeoutExpired (command , 4 , stderr = stderr )
159+ responses = [failure ] if command == "status" else [
160+ self .status (resource (), resource ("r2" )), self .status (resource ()), failure ,
161+ ]
162+ self .run .side_effect = responses
163+ with patch .object (hook , "connect_container_stdout" ):
164+ self .assertEqual (hook .run_hook (), 1 )
165+ self .assertEqual (self .run .call_count , len (responses ))
166+ self .events .assert_called_with (
167+ "abort-no-further-actions" , error_type = "TimeoutExpired" ,
168+ error = str (failure ), stderr = stderr .decode ("utf-8" , errors = "replace" )[- 2048 :],
169+ )
170+
125171 def test_deadline_prevents_further_down_and_bounds_command_timeout (self ):
126172 self .clock .side_effect = [0 , 60 ]
127173 self .run .side_effect = [self .status (resource ()), self .status (resource ())]
0 commit comments