File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 22
33import asyncio
44import warnings
5- from datetime import timedelta
5+ from datetime import datetime , timedelta , timezone
66from typing import TYPE_CHECKING
77
88import pytest
@@ -321,3 +321,26 @@ async def test_get_remaining_time_warns_when_not_at_home(caplog: pytest.LogCaptu
321321 result = Actor ._get_remaining_time ()
322322 assert result is None
323323 assert any ('inherit' in msg or 'RemainingTime' in msg for msg in caplog .messages )
324+
325+
326+ async def test_get_remaining_time_clamps_negative_to_zero () -> None :
327+ """Test that _get_remaining_time returns timedelta(0) instead of a negative value when timeout is in the past."""
328+ async with Actor :
329+ Actor .configuration .is_at_home = True
330+ Actor .configuration .timeout_at = datetime .now (tz = timezone .utc ) - timedelta (minutes = 5 )
331+
332+ result = Actor ._get_remaining_time ()
333+ assert result is not None
334+ assert result == timedelta (0 )
335+
336+
337+ async def test_get_remaining_time_returns_positive_when_timeout_in_future () -> None :
338+ """Test that _get_remaining_time returns a positive timedelta when timeout is in the future."""
339+ async with Actor :
340+ Actor .configuration .is_at_home = True
341+ Actor .configuration .timeout_at = datetime .now (tz = timezone .utc ) + timedelta (minutes = 5 )
342+
343+ result = Actor ._get_remaining_time ()
344+ assert result is not None
345+ assert result > timedelta (0 )
346+ assert result <= timedelta (minutes = 5 )
You can’t perform that action at this time.
0 commit comments