def exception(self, timeout=None, _wait=1): """Return the exception raised by the call, if any. This blocks until the message has successfully been published, and returns the exception. If the call succeeded, return None. Args: timeout (Union[int, float]): The number of seconds before this call times out and raises TimeoutError. Raises: TimeoutError: If the request times out. Returns: Exception: The exception raised by the call, if any. """ # Wait until the future is done. if not self._completed.wait(timeout=timeout): raise exceptions.TimeoutError('Timed out waiting for result.') # If the batch completed successfully, this should return None. if self._result is not None: return None # Okay, this batch had an error; this should return it. return self._exception
def test_handle_webhook_publish_timeout(app, mocker, mock_setup): """ test that if the publish call to pubsub times out, we send a non-200 response """ base_url = "functions.googlecloud.com" function_name = "/" + os.environ["FUNCTION_NAME"] path = "/test_handle_webhook_valid" content = { "merchant_id": "merchant", "location_id": "location", "event_type": "event", "entity_id": "entity" } to_sign = "://" + base_url + function_name + path + json.dumps( content, sort_keys=True) signature = base64.b64encode( hmac.new(KEY.encode(), to_sign.encode(), sha1).digest()) with app.test_request_context(method='POST', path=path, base_url=base_url, json=content, headers={"X-Square-Signature": signature}): with pytest.raises(InternalServerError): mocker.patch.object(pubsub_v1.publisher.futures.Future, "result", side_effect=exceptions.TimeoutError()) main.handle_webhook(flask.request)
def exception(self, timeout=None): """Return the exception raised by the call, if any. Args: timeout (Union[int, float]): The number of seconds before this call times out and raises TimeoutError. Raises: concurrent.futures.TimeoutError: If the request times out. Returns: Exception: The exception raised by the call, if any. """ # Wait until the future is done. if not self._completed.wait(timeout=timeout): raise exceptions.TimeoutError("Timed out waiting for result.") # If the batch completed successfully, this should return None. if self._result != self._SENTINEL: return None # Okay, this batch had an error; this should return it. return self._exception