|
10 | 10 | from app.objects.c_operation import Operation |
11 | 11 | from app.objects.secondclass.c_link import Link |
12 | 12 | from app.service.interfaces.i_event_svc import EventServiceInterface |
| 13 | +from app.service.interfaces.i_planning_svc import PlanningServiceInterface |
13 | 14 | from app.utility.base_service import BaseService |
14 | 15 | from app.objects.c_source import Source |
15 | 16 | from app.objects.c_planner import Planner |
@@ -139,16 +140,43 @@ async def fire_event(self, exchange=None, queue=None, timestamp=True, **callback |
139 | 140 | BaseService.remove_service('event_svc') |
140 | 141 |
|
141 | 142 |
|
| 143 | +@pytest.fixture |
| 144 | +def fake_planning_svc(event_loop, make_test_link, test_agent): |
| 145 | + class FakePlanningService(BaseService, PlanningServiceInterface): |
| 146 | + def __init__(self): |
| 147 | + self.fired = {} |
| 148 | + |
| 149 | + async def get_cleanup_links(self, operation, agent): |
| 150 | + cleanup_link = make_test_link(135, link_paw=test_agent.paw, link_cleanup=1, link_status=0) |
| 151 | + return [cleanup_link] |
| 152 | + |
| 153 | + def get_links(self, operation, buckets, agent, trim): |
| 154 | + pass |
| 155 | + |
| 156 | + def generate_and_trim_links(self, agent, operation, abilities, trim): |
| 157 | + pass |
| 158 | + |
| 159 | + def sort_links(self, links): |
| 160 | + pass |
| 161 | + |
| 162 | + service = FakePlanningService() |
| 163 | + service.add_service('planning_svc', service) |
| 164 | + |
| 165 | + yield service |
| 166 | + |
| 167 | + BaseService.remove_service('planning_svc') |
| 168 | + |
| 169 | + |
142 | 170 | @pytest.fixture |
143 | 171 | def test_ability(ability, executor): |
144 | 172 | return ability(ability_id='123', executors=[executor(name='psh', platform='windows')]) |
145 | 173 |
|
146 | 174 |
|
147 | 175 | @pytest.fixture |
148 | 176 | def make_test_link(test_ability): |
149 | | - def _make_link(link_id, link_paw='123456', link_status=-3): |
| 177 | + def _make_link(link_id, link_paw='123456', link_status=-3, link_cleanup=0): |
150 | 178 | return Link(command='', paw=link_paw, ability=test_ability, id=link_id, executor=next(test_ability.executors), |
151 | | - status=link_status) |
| 179 | + status=link_status, cleanup=link_cleanup) |
152 | 180 | return _make_link |
153 | 181 |
|
154 | 182 |
|
@@ -597,3 +625,11 @@ async def test_add_ignored_link(self, make_test_link, operation_agent): |
597 | 625 | assert op.ignored_links |
598 | 626 | assert test_link.id in op.ignored_links |
599 | 627 | assert len(op.ignored_links) == 1 |
| 628 | + |
| 629 | + async def test_operation_cleanup_status(self, fake_planning_svc, operation_agent): |
| 630 | + services = {'planning_svc': fake_planning_svc} |
| 631 | + op = Operation(name='test with cleanup', agents=[operation_agent], state='running') |
| 632 | + assert op.state == 'running' |
| 633 | + assert await op.is_closeable() |
| 634 | + await op._cleanup_operation(services) |
| 635 | + assert op.state == 'cleanup' |
0 commit comments