File tree Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Expand file tree Collapse file tree 3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,12 @@ def __init__(self, retry=DEFAULT_RETRY):
6666 self ._done_callbacks = []
6767
6868 @abc .abstractmethod
69- def done (self ):
69+ def done (self , retry = DEFAULT_RETRY ):
7070 """Checks to see if the operation is complete.
7171
72+ Args:
73+ retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
74+
7275 Returns:
7376 bool: True if the operation is complete, False otherwise.
7477 """
Original file line number Diff line number Diff line change @@ -145,21 +145,28 @@ def _set_result_from_operation(self):
145145 )
146146 self .set_exception (exception )
147147
148- def _refresh_and_update (self ):
149- """Refresh the operation and update the result if needed."""
148+ def _refresh_and_update (self , retry = polling .DEFAULT_RETRY ):
149+ """Refresh the operation and update the result if needed.
150+
151+ Args:
152+ retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
153+ """
150154 # If the currently cached operation is done, no need to make another
151155 # RPC as it will not change once done.
152156 if not self ._operation .done :
153- self ._operation = self ._refresh ()
157+ self ._operation = self ._refresh (retry = retry )
154158 self ._set_result_from_operation ()
155159
156- def done (self ):
160+ def done (self , retry = polling . DEFAULT_RETRY ):
157161 """Checks to see if the operation is complete.
158162
163+ Args:
164+ retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
165+
159166 Returns:
160167 bool: True if the operation is complete, False otherwise.
161168 """
162- self ._refresh_and_update ()
169+ self ._refresh_and_update (retry )
163170 return self ._operation .done
164171
165172 def cancel (self ):
Original file line number Diff line number Diff line change 1515
1616import mock
1717
18+ from google .api_core import exceptions
1819from google .api_core import operation
1920from google .api_core import operations_v1
21+ from google .api_core import retry
2022from google .longrunning import operations_pb2
2123from google .protobuf import struct_pb2
2224from google .rpc import code_pb2
@@ -113,6 +115,23 @@ def test_result():
113115 assert future .done ()
114116
115117
118+ def test_done_w_retry ():
119+ RETRY_PREDICATE = retry .if_exception_type (exceptions .TooManyRequests )
120+ test_retry = retry .Retry (predicate = RETRY_PREDICATE )
121+
122+ expected_result = struct_pb2 .Struct ()
123+ responses = [
124+ make_operation_proto (),
125+ # Second operation response includes the result.
126+ make_operation_proto (done = True , response = expected_result ),
127+ ]
128+ future , _ , _ = make_operation_future (responses )
129+ future ._refresh = mock .Mock ()
130+
131+ future .done (retry = test_retry )
132+ future ._refresh .assert_called_once_with (retry = test_retry )
133+
134+
116135def test_exception ():
117136 expected_exception = status_pb2 .Status (message = "meep" )
118137 responses = [
You can’t perform that action at this time.
0 commit comments