From 900e793b03106a6c535c0b28f3c7cef90d3fcc09 Mon Sep 17 00:00:00 2001 From: Dushyant Bhatnagar Date: Mon, 22 Jul 2024 10:18:01 -0700 Subject: [PATCH] Increase the post timeout for uploading With larger and larger amounts of data being uploaded by more modern DUTs and tester software, we are seeing runs taking even longer to upload and get responses from servers. PiperOrigin-RevId: 654804315 --- openhtf/output/callbacks/mfg_inspector.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/openhtf/output/callbacks/mfg_inspector.py b/openhtf/output/callbacks/mfg_inspector.py index 349c97a2..863ad440 100644 --- a/openhtf/output/callbacks/mfg_inspector.py +++ b/openhtf/output/callbacks/mfg_inspector.py @@ -18,13 +18,14 @@ import time import zlib +from google.auth import credentials as credentials_lib from google.auth.transport import requests from google.oauth2 import service_account - from openhtf.output import callbacks -from openhtf.output.proto import guzzle_pb2 from openhtf.output.proto import test_runs_converter +from openhtf.output.proto import guzzle_pb2 + class UploadFailedError(Exception): """Raised when an upload to mfg-inspector fails.""" @@ -34,20 +35,25 @@ class InvalidTestRunError(Exception): """Raised if test run is invalid.""" -def _send_mfg_inspector_request(envelope_data, credentials, destination_url): +def _send_mfg_inspector_request( + envelope_data: bytes, + credentials: credentials_lib.Credentials, + destination_url: str, +): """Send upload http request. Intended to be run in retry loop.""" logging.info('Uploading result...') with requests.AuthorizedSession(credentials) as authed_session: response = authed_session.request( - 'POST', destination_url, data=envelope_data) + 'POST', destination_url, data=envelope_data, timeout=60 * 5 + ) try: result = response.json() - except Exception: + except Exception as e: logging.warning('Upload failed with response %s: %s', response, response.text) - raise UploadFailedError(response, response.text) + raise UploadFailedError(response, response.text) from e if response.status_code == 200: return result