Skip to content

Commit

Permalink
cloudtests: allow configuring default timeout for requests (#21976)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrainer-materialize authored Sep 26, 2023
1 parent 29a60de commit becfcb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions misc/python/materialize/cloudtest/util/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def __init__(
self.auth = auth
self.env_kubectl = env_kubectl
self.sys_kubectl = sys_kubectl
self.region_api_requests = WebRequests(self.auth, region_api_server_base_url)
self.region_api_requests = WebRequests(
self.auth, region_api_server_base_url, default_timeout_in_sec=45
)
self.create_env_assignment_get_retries = 120
self.envd_waiting_region_api_timeout = 45
self.envd_waiting_get_env_retries = 900

def create_environment_assignment(
Expand Down Expand Up @@ -66,7 +67,6 @@ def wait_for_environmentd(self, max_attempts: int = 300) -> dict[str, Any]:
def get_environment() -> Response:
response = self.region_api_requests.get(
"/api/region",
self.envd_waiting_region_api_timeout,
)
region_info = response.json().get("regionInfo")
assert region_info
Expand All @@ -92,7 +92,7 @@ def delete_environment() -> None:
# we have a 60 second timeout in the region api's load balancer
# for this call and a 5 minute timeout in the region api (which
# is relevant when running in kind)
timeout=305,
timeout_in_sec=305,
)

retry(delete_environment, 20, [requests.exceptions.HTTPError])
Expand Down
21 changes: 13 additions & 8 deletions misc/python/materialize/cloudtest/util/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ def __init__(
base_url: str,
client_cert: tuple[str, str] | None = None,
additional_headers: dict[str, str] | None = None,
default_timeout_in_sec: int = 15,
):
self.auth = auth
self.base_url = base_url
self.client_cert = client_cert
self.additional_headers = additional_headers
self.default_timeout_in_sec = default_timeout_in_sec

def get(
self,
path: str,
timeout: int = 15,
timeout_in_sec: int | None = None,
) -> requests.Response:
eprint(f"GET {self.base_url}{path}")

Expand All @@ -58,7 +60,7 @@ def try_get() -> requests.Response:
response = requests.get(
f"{self.base_url}{path}",
headers=headers,
timeout=timeout,
timeout=self._timeout_or_default(timeout_in_sec),
cert=self.client_cert,
)
response.raise_for_status()
Expand All @@ -79,7 +81,7 @@ def post(
self,
path: str,
json: Any,
timeout: int = 15,
timeout_in_sec: int | None = None,
) -> requests.Response:
eprint(f"POST {self.base_url}{path}")

Expand All @@ -90,7 +92,7 @@ def try_post() -> requests.Response:
f"{self.base_url}{path}",
headers=headers,
json=json,
timeout=timeout,
timeout=self._timeout_or_default(timeout_in_sec),
cert=self.client_cert,
)
response.raise_for_status()
Expand All @@ -111,7 +113,7 @@ def patch(
self,
path: str,
json: Any,
timeout: int = 15,
timeout_in_sec: int | None = None,
) -> requests.Response:
eprint(f"PATCH {self.base_url}{path}")

Expand All @@ -122,7 +124,7 @@ def try_patch() -> requests.Response:
f"{self.base_url}{path}",
headers=headers,
json=json,
timeout=timeout,
timeout=self._timeout_or_default(timeout_in_sec),
cert=self.client_cert,
)
response.raise_for_status()
Expand All @@ -143,7 +145,7 @@ def delete(
self,
path: str,
params: Any = None,
timeout: int = 15,
timeout_in_sec: int | None = None,
) -> requests.Response:
eprint(f"DELETE {self.base_url}{path}")

Expand All @@ -153,7 +155,7 @@ def try_delete() -> requests.Response:
response = requests.delete(
f"{self.base_url}{path}",
headers=headers,
timeout=timeout,
timeout=self._timeout_or_default(timeout_in_sec),
cert=self.client_cert,
**(
{
Expand Down Expand Up @@ -183,3 +185,6 @@ def _create_headers(self, auth: AuthConfig | None) -> dict[str, Any]:
headers["Authorization"] = f"Bearer {auth.token}"

return headers

def _timeout_or_default(self, timeout_in_sec: int | None) -> int:
return timeout_in_sec or self.default_timeout_in_sec

0 comments on commit becfcb5

Please sign in to comment.