Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 1fdd7ad

Browse files
committed
moved back some fixtures
1 parent 2616894 commit 1fdd7ad

6 files changed

Lines changed: 132 additions & 154 deletions

File tree

tests/system/data/__init__.py

Lines changed: 5 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
TEST_AGGREGATE_FAMILY = "test-aggregate-family"
2424

2525

26-
# authorized view subset to allow all qualifiers
27-
ALLOW_ALL = ""
28-
ALL_QUALIFIERS = {"qualifier_prefixes": [ALLOW_ALL]}
29-
30-
3126
class SystemTestRunner:
3227
"""
3328
configures a system test class with configuration for clusters/tables/etc
@@ -76,124 +71,12 @@ def start_timestamp(self):
7671
"""
7772
return datetime.datetime.now(datetime.timezone.utc)
7873

79-
def _generate_table_id(self):
80-
return f"test-table-{uuid.uuid4().hex}"
81-
82-
@pytest.fixture(scope="session")
83-
def table_id(
84-
self,
85-
admin_client,
86-
project_id,
87-
instance_id,
88-
column_family_config,
89-
init_table_id,
90-
column_split_config,
91-
start_timestamp,
92-
):
93-
"""
94-
Returns BIGTABLE_TEST_TABLE if set, otherwise creates a new temporary table for the test session
95-
96-
Args:
97-
- admin_client: Client for interacting with the Table Admin API. Supplied by the admin_client fixture.
98-
- project_id: The project ID of the GCP project to test against. Supplied by the project_id fixture.
99-
- instance_id: The ID of the Bigtable instance to test against. Supplied by the instance_id fixture.
100-
- init_column_families: A list of column families to initialize the table with, if pre-initialized table is not given with BIGTABLE_TEST_TABLE.
101-
Supplied by the init_column_families fixture.
102-
- init_table_id: The table ID to give to the test table, if pre-initialized table is not given with BIGTABLE_TEST_TABLE.
103-
Supplied by the init_table_id fixture.
104-
- column_split_config: A list of row keys to use as initial splits when creating the test table.
105-
- start_timestamp: accessed when building table to ensure timestamp data is loaded before tests are run
106-
"""
107-
from google.api_core import exceptions
108-
from google.api_core import retry
109-
110-
# use user-specified instance if available
111-
user_specified_table = os.getenv("BIGTABLE_TEST_TABLE")
112-
if user_specified_table:
113-
print("Using user-specified table: {}".format(user_specified_table))
114-
yield user_specified_table
115-
return
116-
117-
retry = retry.Retry(
118-
predicate=retry.if_exception_type(exceptions.FailedPrecondition)
119-
)
120-
try:
121-
parent_path = f"projects/{project_id}/instances/{instance_id}"
122-
print(f"Creating table: {parent_path}/tables/{init_table_id}")
123-
admin_client.table_admin_client.create_table(
124-
request={
125-
"parent": parent_path,
126-
"table_id": init_table_id,
127-
"table": {"column_families": column_family_config},
128-
"initial_splits": [{"key": key} for key in column_split_config],
129-
},
130-
retry=retry,
131-
)
132-
except exceptions.AlreadyExists:
133-
pass
134-
yield init_table_id
135-
print(f"Deleting table: {parent_path}/tables/{init_table_id}")
136-
try:
137-
admin_client.table_admin_client.delete_table(
138-
name=f"{parent_path}/tables/{init_table_id}"
139-
)
140-
except exceptions.NotFound:
141-
print(f"Table {init_table_id} not found, skipping deletion")
142-
14374
@pytest.fixture(scope="session")
144-
def authorized_view_id(
145-
self,
146-
admin_client,
147-
project_id,
148-
instance_id,
149-
table_id,
150-
):
75+
def init_table_id(self, start_timestamp):
15176
"""
152-
Creates and returns a new temporary authorized view for the test session
77+
The table_id to use when creating a new test table
15378
154-
Args:
155-
- admin_client: Client for interacting with the Table Admin API. Supplied by the admin_client fixture.
156-
- project_id: The project ID of the GCP project to test against. Supplied by the project_id fixture.
157-
- instance_id: The ID of the Bigtable instance to test against. Supplied by the instance_id fixture.
158-
- table_id: The ID of the table to create the authorized view for. Supplied by the table_id fixture.
79+
Args
80+
start_timestamp: accessed when building table to ensure timestamp data is loaded before tests are run
15981
"""
160-
from google.api_core import exceptions
161-
from google.api_core import retry
162-
163-
retry = retry.Retry(
164-
predicate=retry.if_exception_type(exceptions.FailedPrecondition)
165-
)
166-
new_view_id = uuid.uuid4().hex[:8]
167-
parent_path = f"projects/{project_id}/instances/{instance_id}/tables/{table_id}"
168-
new_path = f"{parent_path}/authorizedViews/{new_view_id}"
169-
try:
170-
print(f"Creating view: {new_path}")
171-
admin_client.table_admin_client.create_authorized_view(
172-
request={
173-
"parent": parent_path,
174-
"authorized_view_id": new_view_id,
175-
"authorized_view": {
176-
"subset_view": {
177-
"row_prefixes": [ALLOW_ALL],
178-
"family_subsets": {
179-
TEST_FAMILY: ALL_QUALIFIERS,
180-
TEST_FAMILY_2: ALL_QUALIFIERS,
181-
TEST_AGGREGATE_FAMILY: ALL_QUALIFIERS,
182-
},
183-
},
184-
},
185-
},
186-
retry=retry,
187-
)
188-
except exceptions.AlreadyExists:
189-
pass
190-
except exceptions.MethodNotImplemented:
191-
# will occur when run in emulator. Pass empty id
192-
new_view_id = None
193-
yield new_view_id
194-
if new_view_id:
195-
print(f"Deleting view: {new_path}")
196-
try:
197-
admin_client.table_admin_client.delete_authorized_view(name=new_path)
198-
except exceptions.NotFound:
199-
print(f"View {new_view_id} not found, skipping deletion")
82+
return f"test-table-{uuid.uuid4().hex}"

tests/system/data/setup_fixtures.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
import os
2121
import uuid
2222

23+
from . import TEST_FAMILY, TEST_FAMILY_2, TEST_AGGREGATE_FAMILY
24+
25+
# authorized view subset to allow all qualifiers
26+
ALLOW_ALL = ""
27+
ALL_QUALIFIERS = {"qualifier_prefixes": [ALLOW_ALL]}
28+
2329

2430
@pytest.fixture(scope="session")
2531
def admin_client():
@@ -81,6 +87,123 @@ def column_split_config():
8187
return [(num * 1000).to_bytes(8, "big") for num in range(1, 10)]
8288

8389

90+
@pytest.fixture(scope="session")
91+
def table_id(
92+
admin_client,
93+
project_id,
94+
instance_id,
95+
column_family_config,
96+
init_table_id,
97+
column_split_config,
98+
):
99+
"""
100+
Returns BIGTABLE_TEST_TABLE if set, otherwise creates a new temporary table for the test session
101+
102+
Args:
103+
admin_client: Client for interacting with the Table Admin API. Supplied by the admin_client fixture.
104+
project_id: The project ID of the GCP project to test against. Supplied by the project_id fixture.
105+
instance_id: The ID of the Bigtable instance to test against. Supplied by the instance_id fixture.
106+
init_column_families: A list of column families to initialize the table with, if pre-initialized table is not given with BIGTABLE_TEST_TABLE.
107+
Supplied by the init_column_families fixture.
108+
init_table_id: The table ID to give to the test table, if pre-initialized table is not given with BIGTABLE_TEST_TABLE.
109+
Supplied by the init_table_id fixture.
110+
column_split_config: A list of row keys to use as initial splits when creating the test table.
111+
"""
112+
from google.api_core import exceptions
113+
from google.api_core import retry
114+
115+
# use user-specified instance if available
116+
user_specified_table = os.getenv("BIGTABLE_TEST_TABLE")
117+
if user_specified_table:
118+
print("Using user-specified table: {}".format(user_specified_table))
119+
yield user_specified_table
120+
return
121+
122+
retry = retry.Retry(
123+
predicate=retry.if_exception_type(exceptions.FailedPrecondition)
124+
)
125+
try:
126+
parent_path = f"projects/{project_id}/instances/{instance_id}"
127+
print(f"Creating table: {parent_path}/tables/{init_table_id}")
128+
admin_client.table_admin_client.create_table(
129+
request={
130+
"parent": parent_path,
131+
"table_id": init_table_id,
132+
"table": {"column_families": column_family_config},
133+
"initial_splits": [{"key": key} for key in column_split_config],
134+
},
135+
retry=retry,
136+
)
137+
except exceptions.AlreadyExists:
138+
pass
139+
yield init_table_id
140+
print(f"Deleting table: {parent_path}/tables/{init_table_id}")
141+
try:
142+
admin_client.table_admin_client.delete_table(
143+
name=f"{parent_path}/tables/{init_table_id}"
144+
)
145+
except exceptions.NotFound:
146+
print(f"Table {init_table_id} not found, skipping deletion")
147+
148+
149+
@pytest.fixture(scope="session")
150+
def authorized_view_id(
151+
admin_client,
152+
project_id,
153+
instance_id,
154+
table_id,
155+
):
156+
"""
157+
Creates and returns a new temporary authorized view for the test session
158+
159+
Args:
160+
admin_client: Client for interacting with the Table Admin API. Supplied by the admin_client fixture.
161+
project_id: The project ID of the GCP project to test against. Supplied by the project_id fixture.
162+
instance_id: The ID of the Bigtable instance to test against. Supplied by the instance_id fixture.
163+
table_id: The ID of the table to create the authorized view for. Supplied by the table_id fixture.
164+
"""
165+
from google.api_core import exceptions
166+
from google.api_core import retry
167+
168+
retry = retry.Retry(
169+
predicate=retry.if_exception_type(exceptions.FailedPrecondition)
170+
)
171+
new_view_id = uuid.uuid4().hex[:8]
172+
parent_path = f"projects/{project_id}/instances/{instance_id}/tables/{table_id}"
173+
new_path = f"{parent_path}/authorizedViews/{new_view_id}"
174+
try:
175+
print(f"Creating view: {new_path}")
176+
admin_client.table_admin_client.create_authorized_view(
177+
request={
178+
"parent": parent_path,
179+
"authorized_view_id": new_view_id,
180+
"authorized_view": {
181+
"subset_view": {
182+
"row_prefixes": [ALLOW_ALL],
183+
"family_subsets": {
184+
TEST_FAMILY: ALL_QUALIFIERS,
185+
TEST_FAMILY_2: ALL_QUALIFIERS,
186+
TEST_AGGREGATE_FAMILY: ALL_QUALIFIERS,
187+
},
188+
},
189+
},
190+
},
191+
retry=retry,
192+
)
193+
except exceptions.AlreadyExists:
194+
pass
195+
except exceptions.MethodNotImplemented:
196+
# will occur when run in emulator. Pass empty id
197+
new_view_id = None
198+
yield new_view_id
199+
if new_view_id:
200+
print(f"Deleting view: {new_path}")
201+
try:
202+
admin_client.table_admin_client.delete_authorized_view(name=new_path)
203+
except exceptions.NotFound:
204+
print(f"View {new_view_id} not found, skipping deletion")
205+
206+
84207
@pytest.fixture(scope="session")
85208
def project_id(client):
86209
"""Returns the project ID from the client."""

tests/system/data/test_metrics_async.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,6 @@ async def temp_rows(self, table):
214214
yield builder
215215
await builder.delete_rows()
216216

217-
@pytest.fixture(scope="session")
218-
def init_table_id(self):
219-
"""
220-
The table_id to use when creating a new test table
221-
"""
222-
return self._generate_table_id()
223-
224217
@CrossSync.convert
225218
@CrossSync.pytest_fixture(scope="session")
226219
async def table(self, client, table_id, instance_id, handler):

tests/system/data/test_metrics_autogen.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ def temp_rows(self, table):
168168
yield builder
169169
builder.delete_rows()
170170

171-
@pytest.fixture(scope="session")
172-
def init_table_id(self):
173-
"""The table_id to use when creating a new test table"""
174-
return self._generate_table_id()
175-
176171
@pytest.fixture(scope="session")
177172
def table(self, client, table_id, instance_id, handler):
178173
with client.get_table(instance_id, table_id) as table:

tests/system/data/test_system_async.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import uuid
1919
import os
2020
from google.api_core import retry
21-
from google.api_core.exceptions import ClientError, PermissionDenied
21+
from google.api_core.exceptions import ClientError, PermissionDenied, ServerError
2222

2323
from google.cloud.bigtable.data.execute_query.metadata import SqlType
2424
from google.cloud.bigtable.data.read_modify_write_rules import _MAX_INCREMENT_VALUE
@@ -164,16 +164,6 @@ def event_loop(self):
164164
loop.stop()
165165
loop.close()
166166

167-
@pytest.fixture(scope="session")
168-
def init_table_id(self):
169-
"""
170-
The table_id to use when creating a new test table
171-
"""
172-
base_id = self._generate_table_id()
173-
if CrossSync.is_async:
174-
base_id = f"{base_id}-async"
175-
return base_id
176-
177167
def _make_client(self):
178168
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
179169
return CrossSync.DataClient(project=project)
@@ -1354,7 +1344,7 @@ def metrics_client(self, client):
13541344
("application_blocking_latencies", [OperationType.READ_ROWS]),
13551345
],
13561346
)
1357-
@retry.Retry(predicate=retry.if_exception_type(AssertionError))
1347+
@retry.Retry(predicate=retry.if_exception_type(AssertionError, ServerError))
13581348
def test_metric_existence(
13591349
self, client, table_id, metrics_client, start_timestamp, metric, methods
13601350
):

tests/system/data/test_system_autogen.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import uuid
2121
import os
2222
from google.api_core import retry
23-
from google.api_core.exceptions import ClientError, PermissionDenied
23+
from google.api_core.exceptions import ClientError, PermissionDenied, ServerError
2424
from google.cloud.bigtable.data.execute_query.metadata import SqlType
2525
from google.cloud.bigtable.data.read_modify_write_rules import _MAX_INCREMENT_VALUE
2626
from google.cloud.bigtable.data._metrics import OperationType
@@ -127,12 +127,6 @@ def create_row_and_mutation(
127127

128128

129129
class TestSystem(SystemTestRunner):
130-
@pytest.fixture(scope="session")
131-
def init_table_id(self):
132-
"""The table_id to use when creating a new test table"""
133-
base_id = self._generate_table_id()
134-
return base_id
135-
136130
def _make_client(self):
137131
project = os.getenv("GOOGLE_CLOUD_PROJECT") or None
138132
return CrossSync._Sync_Impl.DataClient(project=project)
@@ -1098,7 +1092,7 @@ def metrics_client(self, client):
10981092
("application_blocking_latencies", [OperationType.READ_ROWS]),
10991093
],
11001094
)
1101-
@retry.Retry(predicate=retry.if_exception_type(AssertionError))
1095+
@retry.Retry(predicate=retry.if_exception_type(AssertionError, ServerError))
11021096
def test_metric_existence(
11031097
self, client, table_id, metrics_client, start_timestamp, metric, methods
11041098
):

0 commit comments

Comments
 (0)