Skip to content

Commit

Permalink
added preclean to metricscaler
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Dec 14, 2023
1 parent 72fe36d commit 7a031fc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions samples/metricscaler/metricscaler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@
BIGTABLE_DEV_INSTANCE = INSTANCE_ID_FORMAT.format(str(uuid.uuid4())[:10])


@pytest.fixture(scope="module", autouse=True)
def preclean():
"""In case any test instances weren't cleared out in a previous run.
Deletes any test instances that were created over an hour ago. Newer instances may
be being used by a concurrent test run.
"""
import time
import warnings
prefix = INSTANCE_ID_FORMAT.format("")
client = bigtable.Client(project=PROJECT, admin=True)
for instance in client.list_instances()[0]:
if instance.instance_id.startswith(prefix):
timestamp = instance.instance_id.split("-")[-1]
timestamp = int(timestamp)
if time.time() - timestamp > 3600:
warnings.warn(
f"Deleting leftover test instance: {instance.instance_id}"
)
instance.delete()

# System tests to verify API calls succeed


Expand Down

0 comments on commit 7a031fc

Please sign in to comment.