Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ankiaga committed Feb 7, 2024
1 parent 8b58d0b commit 26efb4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions samples/samples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import time
import uuid
from random import randrange

from google.api_core import exceptions

Expand All @@ -26,8 +27,7 @@
from google.cloud.spanner_v1 import instance
import pytest
from test_utils import retry

from tests.system import _helpers
from test_utils import system

INSTANCE_CREATION_TIMEOUT = 560 # seconds

Expand Down Expand Up @@ -82,17 +82,18 @@ def scrub_instance_ignore_not_found(to_scrub):
@pytest.fixture(scope="session")
def cleanup_old_instances(spanner_client):
"""Delete instances, created by samples, that are older than an hour."""
cutoff = int(time.time()) - 1 * 60 * 60
instance_filter = "labels.cloud_spanner_samples:true"
if CREATE_INSTANCE:
cutoff = int(time.time()) - 1 * 60 * 60
instance_filter = "labels.cloud_spanner_samples:true"

for instance_pb in spanner_client.list_instances(filter_=instance_filter):
inst = instance.Instance.from_pb(instance_pb, spanner_client)
for instance_pb in spanner_client.list_instances(filter_=instance_filter):
inst = instance.Instance.from_pb(instance_pb, spanner_client)

if "created" in inst.labels:
create_time = int(inst.labels["created"])
if "created" in inst.labels:
create_time = int(inst.labels["created"])

if create_time <= cutoff:
scrub_instance_ignore_not_found(inst)
if create_time <= cutoff:
scrub_instance_ignore_not_found(inst)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -202,7 +203,7 @@ def database_id():
Sample testcase modules can override as needed.
"""
return _helpers.unique_id("dbapi-txn")
return unique_id("dbapi-txn")


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -304,3 +305,6 @@ def kms_key_name(spanner_client):
"spanner-test-keyring",
"spanner-test-cmek",
)

def unique_id(prefix, separator="-"):
return f"{prefix}{system.unique_resource_id(separator)}{randrange(100)}"
6 changes: 3 additions & 3 deletions tests/system/test_database_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def test_update_ddl_w_pitr_invalid(
databases_to_delete,
):
pool = spanner_v1.BurstyPool(labels={"testcase": "update_database_ddl_pitr"})
temp_db_id = _helpers.unique_id("pitr_upd_ddl_inv", separator="_")
temp_db_id = _helpers.unique_id("pitr_upd_ddl", separator="_")
retention_period = "0d"
temp_db = shared_instance.database(temp_db_id, pool=pool)

Expand All @@ -367,7 +367,7 @@ def test_update_ddl_w_pitr_success(
databases_to_delete,
):
pool = spanner_v1.BurstyPool(labels={"testcase": "update_database_ddl_pitr"})
temp_db_id = _helpers.unique_id("pitr_upd_ddl_inv", separator="_")
temp_db_id = _helpers.unique_id("pitr_upd_ddl", separator="_")
retention_period = "7d"
temp_db = shared_instance.database(temp_db_id, pool=pool)

Expand Down Expand Up @@ -399,7 +399,7 @@ def test_update_ddl_w_default_leader_success(
labels={"testcase": "update_database_ddl_default_leader"},
)

temp_db_id = _helpers.unique_id("dfl_ldrr_upd_ddl", separator="_")
temp_db_id = _helpers.unique_id("dfl_upd_ddl", separator="_")
default_leader = "us-east4"
temp_db = multiregion_instance.database(temp_db_id, pool=pool)

Expand Down

0 comments on commit 26efb4d

Please sign in to comment.