Debian Codegraph @

tests/i/main_loop/test_auto_restart.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import asyncio
18 from unittest.mock import Mock
19
20 import pytest
21
22 from cylc.flow.main_loop import MainLoopPluginException
23 from cylc.flow.scheduler import Scheduler
24 from cylc.flow.workflow_status import AutoRestartMode
25
26
27 async def test_no_detach(
28 one_conf, flow, scheduler, run, mock_glbl_cfg, log_filter,
29 monkeypatch: pytest.MonkeyPatch
30 ):
31 """Test that the Scheduler aborts when auto restart tries to happen
32 while in no-detach mode."""
33 mock_glbl_cfg(
34 'cylc.flow.scheduler.glbl_cfg', '''
35 [scheduler]
36 [[main loop]]
37 plugins = auto restart
38 [[[auto restart]]]
39 interval = PT1S
40 ''')
41 monkeypatch.setattr(
42 'cylc.flow.main_loop.auto_restart._should_auto_restart',
43 Mock(return_value=AutoRestartMode.RESTART_NORMAL)
44 )
45 id_: str = flow(one_conf)
46 schd: Scheduler = scheduler(id_, paused_start=True, no_detach=True)
47 with pytest.raises(MainLoopPluginException) as exc:
48 async with run(schd):
49 await asyncio.sleep(2)
50 assert log_filter(contains=f"Workflow shutting down - {exc.value}")