Skip to content

Commit

Permalink
Improve error handling for NeonAPI fixture
Browse files Browse the repository at this point in the history
Move error handling to the common request function and add a debug log.

Signed-off-by: Tristan Partin <tristan@neon.tech>
  • Loading branch information
tristan957 authored Nov 14, 2024
1 parent b4e00b8 commit 1280b70
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions test_runner/fixtures/neon_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import requests

from fixtures.log_helper import log

if TYPE_CHECKING:
from typing import Any, Literal, Optional

Expand All @@ -30,7 +32,11 @@ def __request(self, method: str | bytes, endpoint: str, **kwargs: Any) -> reques
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = f"Bearer {self.__neon_api_key}"

return requests.request(method, f"{self.__neon_api_base_url}{endpoint}", **kwargs)
resp = requests.request(method, f"{self.__neon_api_base_url}{endpoint}", **kwargs)
log.debug("%s %s returned a %d: %s", method, endpoint, resp.status_code, resp.text)
resp.raise_for_status()

return resp

def create_project(
self,
Expand Down Expand Up @@ -66,8 +72,6 @@ def create_project(
json=data,
)

assert resp.status_code == 201

return cast("dict[str, Any]", resp.json())

def get_project_details(self, project_id: str) -> dict[str, Any]:
Expand All @@ -79,7 +83,7 @@ def get_project_details(self, project_id: str) -> dict[str, Any]:
"Content-Type": "application/json",
},
)
assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def delete_project(
Expand All @@ -95,8 +99,6 @@ def delete_project(
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def start_endpoint(
Expand All @@ -112,8 +114,6 @@ def start_endpoint(
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def suspend_endpoint(
Expand All @@ -129,8 +129,6 @@ def suspend_endpoint(
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def restart_endpoint(
Expand All @@ -146,8 +144,6 @@ def restart_endpoint(
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def create_endpoint(
Expand Down Expand Up @@ -178,8 +174,6 @@ def create_endpoint(
json=data,
)

assert resp.status_code == 201

return cast("dict[str, Any]", resp.json())

def get_connection_uri(
Expand All @@ -206,8 +200,6 @@ def get_connection_uri(
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def get_branches(self, project_id: str) -> dict[str, Any]:
Expand All @@ -219,8 +211,6 @@ def get_branches(self, project_id: str) -> dict[str, Any]:
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def get_endpoints(self, project_id: str) -> dict[str, Any]:
Expand All @@ -232,8 +222,6 @@ def get_endpoints(self, project_id: str) -> dict[str, Any]:
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def get_operations(self, project_id: str) -> dict[str, Any]:
Expand All @@ -246,8 +234,6 @@ def get_operations(self, project_id: str) -> dict[str, Any]:
},
)

assert resp.status_code == 200

return cast("dict[str, Any]", resp.json())

def wait_for_operation_to_finish(self, project_id: str):
Expand Down

1 comment on commit 1280b70

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5491 tests run: 5252 passed, 2 failed, 237 skipped (full report)


Failures on Postgres 16

# Run all failed tests locally:
scripts/pytest -vv -n $(nproc) -k "test_sharded_ingest[release-pg16-github-actions-selfhosted-1] or test_compaction_l0_memory[release-pg16-github-actions-selfhosted]"
Flaky tests (1)

Postgres 15

Code coverage* (full report)

  • functions: 31.8% (7889 of 24837 functions)
  • lines: 49.4% (62439 of 126301 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
1280b70 at 2024-11-14T04:22:58.990Z :recycle:

Please sign in to comment.