@@ -705,10 +705,8 @@ async def __anext__(self):
705
705
return CustomIterable (n )
706
706
707
707
if awaitale_wrapped :
708
-
709
708
async def wrapper (n ):
710
709
return iterable_fn (n )
711
-
712
710
decorated = retry_ (wrapper )
713
711
else :
714
712
decorated = retry_ (iterable_fn )
@@ -720,6 +718,7 @@ async def wrapper(n):
720
718
await retryable .asend ("test2" ) == 2
721
719
await retryable .asend ("test3" ) == 3
722
720
721
+
723
722
@pytest .mark .parametrize ("awaitale_wrapped" , [True , False ])
724
723
@mock .patch ("asyncio.sleep" , autospec = True )
725
724
@pytest .mark .asyncio
@@ -745,12 +744,9 @@ async def __anext__(self):
745
744
return self .i - 1
746
745
747
746
return CustomIterable (n )
748
-
749
747
if awaitale_wrapped :
750
-
751
748
async def wrapper (n ):
752
749
return iterable_fn (n )
753
-
754
750
decorated = retry_ (wrapper )
755
751
else :
756
752
decorated = retry_ (iterable_fn )
@@ -767,6 +763,7 @@ async def wrapper(n):
767
763
with pytest .raises (StopAsyncIteration ):
768
764
await new_retryable .__anext__ ()
769
765
766
+
770
767
@pytest .mark .parametrize ("awaitale_wrapped" , [True , False ])
771
768
@mock .patch ("asyncio.sleep" , autospec = True )
772
769
@pytest .mark .asyncio
@@ -794,12 +791,9 @@ async def __anext__(self):
794
791
return self .i - 1
795
792
796
793
return CustomIterable (n )
797
-
798
794
if awaitale_wrapped :
799
-
800
795
async def wrapper (n ):
801
796
return iterable_fn (n )
802
-
803
797
decorated = retry_ (wrapper )
804
798
else :
805
799
decorated = retry_ (iterable_fn )
@@ -821,66 +815,6 @@ async def wrapper(n):
821
815
with pytest .raises (StopAsyncIteration ):
822
816
await new_retryable .__anext__ ()
823
817
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
-
884
818
@pytest .mark .asyncio
885
819
async def test_exc_factory_non_retryable_error (self ):
886
820
"""
@@ -937,7 +871,7 @@ async def test_exc_factory_timeout(self):
937
871
938
872
with now_patcher as patched_now :
939
873
timeout = 2
940
- sent_errors = [ValueError ("test" ), ValueError ("test2" )]
874
+ sent_errors = [ValueError ("test" ), ValueError ("test2" ), ValueError ( "test3" ) ]
941
875
expected_final_err = RuntimeError ("done" )
942
876
expected_source_err = ZeroDivisionError ("test4" )
943
877
@@ -954,7 +888,6 @@ def factory(*args, **kwargs):
954
888
[0 ] * 3 ,
955
889
timeout = timeout ,
956
890
exception_factory = factory ,
957
- check_timeout_on_yield = True ,
958
891
)
959
892
# initialize the generator
960
893
await generator .__anext__ ()
@@ -964,6 +897,6 @@ def factory(*args, **kwargs):
964
897
# trigger a timeout
965
898
patched_now .return_value += timeout + 1
966
899
with pytest .raises (expected_final_err .__class__ ) as exc_info :
967
- await generator .__anext__ ( )
900
+ await generator .athrow ( sent_errors [ 2 ] )
968
901
assert exc_info .value == expected_final_err
969
902
assert exc_info .value .__cause__ == expected_source_err
0 commit comments