Skip to content

Commit b0cc5a7

Browse files
committed
Update tests
1 parent 74de324 commit b0cc5a7

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/apify/_actor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ async def start(
734734
serialized_webhooks = None
735735

736736
if timeout == 'RemainingTime':
737-
actor_start_timeout = await self._get_remaining_time()
737+
actor_start_timeout = self._get_remaining_time()
738738
elif isinstance(timeout, str):
739739
raise ValueError(
740740
f'`timeout` can be `None`, `RemainingTime` literal or `timedelta` instance, but is {timeout=}'
@@ -754,7 +754,7 @@ async def start(
754754

755755
return ActorRun.model_validate(api_result)
756756

757-
async def _get_remaining_time(self) -> timedelta | None:
757+
def _get_remaining_time(self) -> timedelta | None:
758758
"""Get time remaining from the actor timeout. Returns `None` if not on an Apify platform."""
759759
if self.is_at_home() and self.configuration.timeout_at:
760760
return self.configuration.timeout_at - datetime.now(tz=timezone.utc)
@@ -846,7 +846,7 @@ async def call(
846846
serialized_webhooks = None
847847

848848
if timeout == 'RemainingTime':
849-
actor_call_timeout = await self._get_remaining_time()
849+
actor_call_timeout = self._get_remaining_time()
850850
elif isinstance(timeout, str):
851851
raise ValueError(
852852
f'`timeout` can be `None`, `RemainingTime` literal or `timedelta` instance, but is {timeout=}'

tests/integration/test_actor_call_timeouts.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,26 @@ async def main() -> None:
2121
if actor_input.get('called_from_another_actor', False) is True:
2222
return
2323

24-
await asyncio.sleep(1)
2524
# Start another run of this actor with timeout set to the time remaining in this actor run
26-
other_run_data = await Actor.start(
25+
other_run_data = await Actor.call(
2726
actor_id=Actor.configuration.actor_id or '',
2827
run_input={'called_from_another_actor': True},
2928
timeout='RemainingTime',
3029
)
31-
32-
# To make sure that the actor is started
33-
await asyncio.sleep(5)
34-
35-
assert Actor.configuration.timeout_at is not None
36-
assert Actor.configuration.started_at is not None
3730
assert other_run_data is not None
38-
assert other_run_data.options is not None
31+
try:
32+
# To make sure that the actor is started
33+
await asyncio.sleep(5)
34+
assert other_run_data.options is not None
35+
assert Actor.configuration.timeout_at is not None
36+
assert Actor.configuration.started_at is not None
3937

40-
remaining_time_after_actor_start = Actor.configuration.timeout_at - datetime.now(tz=timezone.utc)
38+
remaining_time_after_actor_start = Actor.configuration.timeout_at - datetime.now(tz=timezone.utc)
4139

42-
try:
4340
assert other_run_data.options.timeout > remaining_time_after_actor_start
4441
assert other_run_data.options.timeout < Actor.configuration.timeout_at - Actor.configuration.started_at
4542
finally:
46-
# Abort the other actor run after asserting the timeouts
43+
# Make sure the other actor run is aborted
4744
await Actor.apify_client.run(other_run_data.id).abort()
4845

4946
actor = await make_actor(label='remaining-timeout', main_func=main)
@@ -65,28 +62,29 @@ async def main() -> None:
6562
return
6663

6764
await asyncio.sleep(1)
65+
6866
# Start another run of this actor with timeout set to the time remaining in this actor run
6967
other_run_data = await Actor.call(
7068
actor_id=Actor.configuration.actor_id or '',
7169
run_input={'called_from_another_actor': True},
7270
timeout='RemainingTime',
7371
)
7472

75-
# To make sure that the actor is started
76-
await asyncio.sleep(5)
77-
78-
assert Actor.configuration.timeout_at is not None
79-
assert Actor.configuration.started_at is not None
8073
assert other_run_data is not None
81-
assert other_run_data.options is not None
74+
try:
75+
# To make sure that the actor is started
76+
await asyncio.sleep(5)
8277

83-
remaining_time_after_actor_start = Actor.configuration.timeout_at - datetime.now(tz=timezone.utc)
78+
assert other_run_data.options is not None
79+
assert Actor.configuration.timeout_at is not None
80+
assert Actor.configuration.started_at is not None
81+
82+
remaining_time_after_actor_start = Actor.configuration.timeout_at - datetime.now(tz=timezone.utc)
8483

85-
try:
8684
assert other_run_data.options.timeout > remaining_time_after_actor_start
8785
assert other_run_data.options.timeout < Actor.configuration.timeout_at - Actor.configuration.started_at
8886
finally:
89-
# Abort the other actor run after asserting the timeouts
87+
# Make sure the other actor run is aborted
9088
await Actor.apify_client.run(other_run_data.id).abort()
9189

9290
actor = await make_actor(label='remaining-timeout', main_func=main)

0 commit comments

Comments
 (0)