19
19
import shutil
20
20
from glob import iglob
21
21
from pathlib import Path
22
+ from subprocess import Popen
22
23
from typing import (
23
24
Any ,
24
25
Callable ,
@@ -274,7 +275,8 @@ def test_init_clean__rm_dirs(
274
275
init_clean (id_ , opts = opts )
275
276
mock_clean .assert_called_with (id_ , run_dir , expected_clean )
276
277
mock_remote_clean .assert_called_with (
277
- id_ , platforms , expected_remote_clean , opts .remote_timeout )
278
+ id_ , platforms , opts .remote_timeout , expected_remote_clean
279
+ )
278
280
279
281
280
282
@pytest .mark .parametrize (
@@ -920,7 +922,7 @@ def test_remote_clean(
920
922
# Remove randomness:
921
923
monkeymock ('cylc.flow.clean.shuffle' )
922
924
923
- def mocked_remote_clean_cmd_side_effect (id_ , platform , rm_dirs , timeout ):
925
+ def mocked_remote_clean_cmd_side_effect (id_ , platform , timeout , rm_dirs ):
924
926
proc_ret_code = 0
925
927
if failed_platforms and platform ['name' ] in failed_platforms :
926
928
proc_ret_code = failed_platforms [platform ['name' ]]
@@ -942,11 +944,13 @@ def mocked_remote_clean_cmd_side_effect(id_, platform, rm_dirs, timeout):
942
944
if exc_expected :
943
945
with pytest .raises (CylcError ) as exc :
944
946
cylc_clean .remote_clean (
945
- id_ , platform_names , rm_dirs , timeout = 'irrelevant' )
947
+ id_ , platform_names , timeout = 'irrelevant' , rm_dirs = rm_dirs
948
+ )
946
949
assert "Remote clean failed" in str (exc .value )
947
950
else :
948
951
cylc_clean .remote_clean (
949
- id_ , platform_names , rm_dirs , timeout = 'irrelevant' )
952
+ id_ , platform_names , timeout = 'irrelevant' , rm_dirs = rm_dirs
953
+ )
950
954
for msg in expected_err_msgs :
951
955
assert log_filter (caplog , level = logging .ERROR , contains = msg )
952
956
if expected_platforms :
@@ -960,6 +964,36 @@ def mocked_remote_clean_cmd_side_effect(id_, platform, rm_dirs, timeout):
960
964
assert f"{ p_name } - { PlatformError .MSG_TIDY } " in caplog .text
961
965
962
966
967
+ def test_remote_clean__timeout (
968
+ monkeymock : MonkeyMock ,
969
+ monkeypatch : pytest .MonkeyPatch ,
970
+ caplog : pytest .LogCaptureFixture ,
971
+ ):
972
+ """Test remote_clean() gives a sensible error message for return code 124.
973
+ """
974
+ caplog .set_level (logging .ERROR , CYLC_LOG )
975
+ monkeymock (
976
+ 'cylc.flow.clean._remote_clean_cmd' ,
977
+ spec = _remote_clean_cmd ,
978
+ return_value = mock .Mock (
979
+ spec = Popen , poll = lambda : 124 , communicate = lambda : ('' , '' )
980
+ )
981
+ )
982
+ monkeypatch .setattr (
983
+ 'cylc.flow.clean.get_install_target_to_platforms_map' ,
984
+ lambda * a , ** k : {'picard' : [PLATFORMS ['stargazer' ]]}
985
+ )
986
+
987
+ with pytest .raises (CylcError ):
988
+ cylc_clean .remote_clean (
989
+ 'blah' , platform_names = ['blah' ], timeout = 'blah'
990
+ )
991
+ assert "cylc clean timed out" in caplog .text
992
+ # No need to log the remote clean cmd etc. for timeout
993
+ assert "ssh" not in caplog .text .lower ()
994
+ assert "stderr" not in caplog .text .lower ()
995
+
996
+
963
997
@pytest .mark .parametrize (
964
998
'rm_dirs, expected_args' ,
965
999
[
0 commit comments