@@ -94,6 +94,7 @@ def test_client_settings_creation(self):
9494 assert settings .timeout == 30.0
9595 assert settings .poll_interval == 0.5
9696 assert settings .max_file_size == 5 * 1024 * 1024
97+ assert settings .monitor is True # Default is True
9798
9899 def test_client_settings_custom_values (self ):
99100 """Test creating client settings with custom values."""
@@ -103,13 +104,15 @@ def test_client_settings_custom_values(self):
103104 timeout = 60.0 ,
104105 poll_interval = 1.0 ,
105106 max_file_size = 10 * 1024 * 1024 ,
107+ monitor = False ,
106108 )
107109
108110 assert str (settings .server_url ) == "http://192.168.1.100:9000/"
109111 assert settings .token .get_secret_value () == "custom-token"
110112 assert settings .timeout == 60.0
111113 assert settings .poll_interval == 1.0
112114 assert settings .max_file_size == 10 * 1024 * 1024
115+ assert settings .monitor is False
113116
114117
115118class TestJobResult :
@@ -234,14 +237,25 @@ def test_wait_for_result_success(self, rpc_client: XmlRpcClient):
234237 assert result .returncode == 0
235238 assert "completed" in result .stdout
236239
237- def test_wait_for_result_timeout (self , rpc_client : XmlRpcClient ):
238- """Test timeout when waiting for command completion."""
240+ def test_wait_for_result_timeout (self , test_server ):
241+ """Test timeout when waiting for command completion (with monitor=False) ."""
239242 import sys
240243
241- submission = rpc_client .submit_command ([sys .executable , "-c" , "import time; time.sleep(10)" ])
244+ # Create a client with monitor=False to test actual timeout behavior
245+ _ , port , token = test_server
246+ settings = XmlRpcClientSettings (
247+ server_url = HttpUrl (f"http://127.0.0.1:{ port } " ),
248+ token = SecretStr (token ),
249+ timeout = 5.0 ,
250+ poll_interval = 0.1 ,
251+ monitor = False , # Disable monitor mode to test hard timeout
252+ )
253+ client = XmlRpcClient (settings )
254+
255+ submission = client .submit_command ([sys .executable , "-c" , "import time; time.sleep(10)" ])
242256
243257 with pytest .raises (TimeoutError , match = "did not complete within" ):
244- rpc_client .wait_for_result (submission .job_id , timeout = 0.5 )
258+ client .wait_for_result (submission .job_id , timeout = 0.5 )
245259
246260 def test_run_command_success (self , rpc_client : XmlRpcClient ):
247261 """Test running a command to completion."""
@@ -267,6 +281,49 @@ def test_is_running(self, rpc_client: XmlRpcClient):
267281 is_running_after = rpc_client .is_running (submission .job_id )
268282 assert is_running_after is False
269283
284+ def test_wait_for_result_with_monitor_default (self , rpc_client : XmlRpcClient ):
285+ """Test that monitor mode (default) completes successfully for long-running job."""
286+ import sys
287+
288+ # Submit a job that runs longer than the timeout
289+ submission = rpc_client .submit_command ([sys .executable , "-c" , "import time; time.sleep(0.5); print('done')" ])
290+
291+ # The job takes 0.5s but timeout is 0.3s - with default monitor=True,
292+ # the timeout resets each time is_running returns True
293+ result = rpc_client .wait_for_result (submission .job_id , timeout = 0.3 )
294+
295+ assert result .status == JobStatus .DONE
296+ assert result .returncode == 0
297+ assert "done" in result .stdout
298+
299+ def test_wait_for_result_monitor_resets_timeout (self , rpc_client : XmlRpcClient ):
300+ """Test that monitor mode (default) resets timeout when job is confirmed running."""
301+ import sys
302+
303+ # Submit a job that takes longer than the timeout
304+ submission = rpc_client .submit_command (
305+ [sys .executable , "-c" , "import time; time.sleep(0.8); print('finished')" ]
306+ )
307+
308+ # With default monitor=True, the timeout resets each poll cycle while job is running
309+ result = rpc_client .wait_for_result (submission .job_id , timeout = 0.4 )
310+
311+ assert result .status == JobStatus .DONE
312+ assert "finished" in result .stdout
313+
314+ def test_run_command_with_monitor_default (self , rpc_client : XmlRpcClient ):
315+ """Test run_command with default monitor mode enabled."""
316+ import sys
317+
318+ # With default monitor=True, long-running commands complete successfully
319+ result = rpc_client .run_command (
320+ [sys .executable , "-c" , "import time; time.sleep(0.5); print('monitored')" ],
321+ timeout = 0.3 ,
322+ )
323+
324+ assert result .status == JobStatus .DONE
325+ assert "monitored" in result .stdout
326+
270327 def test_list_jobs (self , rpc_client : XmlRpcClient ):
271328 """Test listing jobs."""
272329 # Submit a job
0 commit comments