示例#1
0
async def test_other_error_details_present():
    any1 = Any()
    any1.Pack(RetryInfo())
    any2 = Any()
    any2.Pack(ErrorInfo(reason="RESET", domain="pubsublite.googleapis.com"))
    status_pb = Status(code=10, details=[any1, any2])
    assert is_reset_signal(Aborted("", response=make_call(status_pb)))
示例#2
0
    async def stop_processing(self, error: GoogleAPICallError):
        await self._stop_loopers()
        if is_reset_signal(error):
            # Discard undelivered messages and refill flow control tokens.
            while not self._message_queue.empty():
                batch: List[SequencedMessage.meta.pb] = self._message_queue.get_nowait()
                allowed_bytes = sum(message.size_bytes for message in batch)
                self._outstanding_flow_control.add(
                    FlowControlRequest(
                        allowed_messages=len(batch), allowed_bytes=allowed_bytes,
                    )
                )

            await self._reset_handler.handle_reset()
            self._last_received_offset = None
 async def reinitialize(
     self,
     connection: Connection[SubscribeRequest, SubscribeResponse],
     last_error: Optional[GoogleAPICallError],
 ):
     self._reinitializing = True
     await self._stop_loopers()
     if last_error and is_reset_signal(last_error):
         # Discard undelivered messages and refill flow control tokens.
         while not self._message_queue.empty():
             msg = self._message_queue.get_nowait()
             self._outstanding_flow_control.add(
                 FlowControlRequest(
                     allowed_messages=1,
                     allowed_bytes=msg.size_bytes,
                 ))
         await self._reset_handler.handle_reset()
         self._last_received_offset = None
     initial = deepcopy(self._base_initial)
     if self._last_received_offset is not None:
         initial.initial_location = SeekRequest(cursor=Cursor(
             offset=self._last_received_offset + 1))
     else:
         initial.initial_location = SeekRequest(
             named_target=SeekRequest.NamedTarget.COMMITTED_CURSOR)
     await connection.write(SubscribeRequest(initial=initial))
     response = await connection.read()
     if "initial" not in response:
         self._connection.fail(
             FailedPrecondition(
                 "Received an invalid initial response on the subscribe stream."
             ))
         return
     tokens = self._outstanding_flow_control.request_for_restart()
     if tokens is not None:
         await connection.write(SubscribeRequest(flow_control=tokens))
     self._reinitializing = False
     self._start_loopers()
示例#4
0
async def test_wrong_error_detail():
    any = Any()
    any.Pack(RetryInfo())
    status_pb = Status(code=10, details=[any])
    assert not is_reset_signal(Aborted("", response=make_call(status_pb)))
示例#5
0
async def test_wrong_domain():
    any = Any()
    any.Pack(ErrorInfo(reason="RESET", domain="other.googleapis.com"))
    status_pb = Status(code=10, details=[any])
    assert not is_reset_signal(Aborted("", response=make_call(status_pb)))
示例#6
0
async def test_extracted_status_is_none():
    status_pb = Status(code=10, details=[])
    assert not is_reset_signal(
        Aborted("", response=make_call_without_metadata(status_pb))
    )
示例#7
0
async def test_missing_call():
    assert not is_reset_signal(Aborted(""))
示例#8
0
async def test_non_retryable():
    assert not is_reset_signal(NotFound(""))
示例#9
0
async def test_is_reset_signal():
    assert is_reset_signal(make_reset_signal())