Skip to content

Commit 3a7e5fa

Browse files
committed
removed timeout on yield functionality
1 parent cee0028 commit 3a7e5fa

File tree

2 files changed

+4
-77
lines changed

2 files changed

+4
-77
lines changed

google/api_core/retry_streaming_async.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ async def retry_target_generator(
5757
[List[Exception], bool, float], Tuple[Exception, Optional[Exception]]
5858
]
5959
] = None,
60-
check_timeout_on_yield: bool = False,
6160
**kwargs,
6261
) -> AsyncGenerator[T, None]:
6362
subgenerator = None
@@ -87,11 +86,6 @@ async def retry_target_generator(
8786

8887
sent_in = None
8988
while True:
90-
# Check for expiration before starting
91-
if check_timeout_on_yield is True and deadline is not None and time.monotonic() > deadline:
92-
exc, source_exc = exc_factory(exc_list=error_list, is_timeout=True)
93-
exc.__cause__ = source_exc
94-
raise _TerminalException() from exc
9589
## Read from Subgenerator
9690
if supports_send:
9791
next_value = await subgenerator.asend(sent_in)

tests/asyncio/test_retry_async.py

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,8 @@ async def __anext__(self):
705705
return CustomIterable(n)
706706

707707
if awaitale_wrapped:
708-
709708
async def wrapper(n):
710709
return iterable_fn(n)
711-
712710
decorated = retry_(wrapper)
713711
else:
714712
decorated = retry_(iterable_fn)
@@ -720,6 +718,7 @@ async def wrapper(n):
720718
await retryable.asend("test2") == 2
721719
await retryable.asend("test3") == 3
722720

721+
723722
@pytest.mark.parametrize("awaitale_wrapped", [True, False])
724723
@mock.patch("asyncio.sleep", autospec=True)
725724
@pytest.mark.asyncio
@@ -745,12 +744,9 @@ async def __anext__(self):
745744
return self.i - 1
746745

747746
return CustomIterable(n)
748-
749747
if awaitale_wrapped:
750-
751748
async def wrapper(n):
752749
return iterable_fn(n)
753-
754750
decorated = retry_(wrapper)
755751
else:
756752
decorated = retry_(iterable_fn)
@@ -767,6 +763,7 @@ async def wrapper(n):
767763
with pytest.raises(StopAsyncIteration):
768764
await new_retryable.__anext__()
769765

766+
770767
@pytest.mark.parametrize("awaitale_wrapped", [True, False])
771768
@mock.patch("asyncio.sleep", autospec=True)
772769
@pytest.mark.asyncio
@@ -794,12 +791,9 @@ async def __anext__(self):
794791
return self.i - 1
795792

796793
return CustomIterable(n)
797-
798794
if awaitale_wrapped:
799-
800795
async def wrapper(n):
801796
return iterable_fn(n)
802-
803797
decorated = retry_(wrapper)
804798
else:
805799
decorated = retry_(iterable_fn)
@@ -821,66 +815,6 @@ async def wrapper(n):
821815
with pytest.raises(StopAsyncIteration):
822816
await new_retryable.__anext__()
823817

824-
@pytest.mark.parametrize("yield_method", ["__anext__", "asend"])
825-
@mock.patch("asyncio.sleep", autospec=True)
826-
@pytest.mark.asyncio
827-
async def test_yield_stream_after_deadline(self, sleep, yield_method):
828-
"""
829-
By default, if the deadline is hit between yields, the generator will continue.
830-
831-
There is a flag that should cause the wrapper to test for the deadline after
832-
each yield.
833-
"""
834-
import time
835-
import functools
836-
from google.api_core.retry_streaming_async import retry_target_generator
837-
838-
timeout = 2
839-
time_now = time.monotonic()
840-
now_patcher = mock.patch(
841-
"time.monotonic",
842-
return_value=time_now,
843-
)
844-
845-
with now_patcher as patched_now:
846-
no_check = retry_target_generator(
847-
self._generator_mock,
848-
None,
849-
[0] * 10,
850-
timeout=timeout,
851-
check_timeout_on_yield=False,
852-
)
853-
check = retry_target_generator(
854-
self._generator_mock,
855-
None,
856-
[0] * 10,
857-
timeout=timeout,
858-
check_timeout_on_yield=True,
859-
)
860-
861-
# initialize the generator
862-
await no_check.__anext__()
863-
await check.__anext__()
864-
865-
# use yield_method to advance the generator
866-
no_check_yield = getattr(no_check, yield_method)
867-
check_yield = getattr(check, yield_method)
868-
if yield_method == "asend":
869-
no_check_yield = functools.partial(no_check_yield, None)
870-
check_yield = functools.partial(check_yield, None)
871-
872-
# first yield should be fine
873-
await check_yield()
874-
await no_check_yield()
875-
876-
# simulate a delay before next yield
877-
patched_now.return_value += timeout + 1
878-
879-
# second yield should raise when check_timeout_on_yield is True
880-
with pytest.raises(exceptions.RetryError):
881-
await check_yield()
882-
await no_check_yield()
883-
884818
@pytest.mark.asyncio
885819
async def test_exc_factory_non_retryable_error(self):
886820
"""
@@ -937,7 +871,7 @@ async def test_exc_factory_timeout(self):
937871

938872
with now_patcher as patched_now:
939873
timeout = 2
940-
sent_errors = [ValueError("test"), ValueError("test2")]
874+
sent_errors = [ValueError("test"), ValueError("test2"), ValueError("test3")]
941875
expected_final_err = RuntimeError("done")
942876
expected_source_err = ZeroDivisionError("test4")
943877

@@ -954,7 +888,6 @@ def factory(*args, **kwargs):
954888
[0] * 3,
955889
timeout=timeout,
956890
exception_factory=factory,
957-
check_timeout_on_yield=True,
958891
)
959892
# initialize the generator
960893
await generator.__anext__()
@@ -964,6 +897,6 @@ def factory(*args, **kwargs):
964897
# trigger a timeout
965898
patched_now.return_value += timeout + 1
966899
with pytest.raises(expected_final_err.__class__) as exc_info:
967-
await generator.__anext__()
900+
await generator.athrow(sent_errors[2])
968901
assert exc_info.value == expected_final_err
969902
assert exc_info.value.__cause__ == expected_source_err

0 commit comments

Comments
 (0)