|
| 1 | +import asyncio |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from apify import Actor |
| 6 | +from tests.integration.conftest import MakeActorFunction, RunActorFunction |
| 7 | + |
| 8 | + |
| 9 | +async def test_actor_start_remaining_timeout( |
| 10 | + make_actor: MakeActorFunction, |
| 11 | + run_actor: RunActorFunction, |
| 12 | +) -> None: |
| 13 | + async def main() -> None: |
| 14 | + async with Actor: |
| 15 | + actor_input = (await Actor.get_input()) or {} |
| 16 | + if actor_input.get("called_from_another_actor",False) is True: |
| 17 | + # Do nothing and only wait for |
| 18 | + await asyncio.sleep(1000) |
| 19 | + return |
| 20 | + |
| 21 | + |
| 22 | + self_run_client = Actor.apify_client.run(Actor.configuration.actor_run_id) |
| 23 | + self_run_data_1 = await self_run_client.get() |
| 24 | + run_time_1 = self_run_data_1.get('runTimeSecs', 0) |
| 25 | + self_timeout = self_run_data_1.get('options', {}).get('timeoutSecs', 0) |
| 26 | + |
| 27 | + # Start another run of this actor with timeout set to the time remaining in this actor |
| 28 | + other_run_data = await Actor.start(actor_id=Actor.configuration.actor_id, |
| 29 | + run_input={"called_from_another_actor": True}, |
| 30 | + timeout="RemainingTime") |
| 31 | + |
| 32 | + self_run_data_2 = await self_run_client.get() |
| 33 | + run_time_2 = self_run_data_2.get('runTimeSecs', 0) |
| 34 | + other_actor_timeout = other_run_data.get('options', {}).get('timeoutSecs', 0) |
| 35 | + |
| 36 | + assert other_actor_timeout > self_timeout - run_time_1 |
| 37 | + assert other_actor_timeout < self_timeout - run_time_2 |
| 38 | + |
| 39 | + actor = await make_actor(label='remaining timeout', main_func=main) |
| 40 | + run_result = await run_actor(actor) |
| 41 | + |
| 42 | + assert run_result.status == 'SUCCEEDED' |
0 commit comments