Skip to content

Commit

Permalink
test: cleanup capacity commitments leftover from failed samples tests (
Browse files Browse the repository at this point in the history
…#224)

* test: cleanup capacity commitments leftover from failed samples tests

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* try session scope

* handle failed commitments in cleanup

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people authored and dandhlee committed Jul 24, 2023
1 parent 0939146 commit 3553a50
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bigquery-reservation/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
import pytest


@pytest.fixture(scope="session", autouse=True)
def cleanup_commitments(
reservation_client: reservation_service.ReservationServiceClient, location_path: str
) -> None:
for commitment in reservation_client.list_capacity_commitments(
parent=location_path
):
if commitment.state == reservation_types.CapacityCommitment.State.FAILED or (
commitment.commitment_start_time is not None
and commitment.commitment_start_time
< datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=1)
):
reservation_client.delete_capacity_commitment(name=commitment.name)


@pytest.fixture(scope="session")
def project_id() -> str:
return os.environ["GOOGLE_CLOUD_PROJECT"]
Expand All @@ -47,8 +62,6 @@ def location_path(project_id: str, location: str) -> str:
def capacity_commitment(
location_path: str, reservation_client: reservation_service.ReservationServiceClient
) -> reservation_types.CapacityCommitment:
# TODO(b/196082966): If custom names or creation date property are added,
# do pre-test cleanup of past commitments.
commitment = reservation_types.CapacityCommitment()
commitment.slot_count = 100
commitment.plan = reservation_types.CapacityCommitment.CommitmentPlan.FLEX
Expand Down

0 comments on commit 3553a50

Please sign in to comment.