Skip to content

Commit 944e8fd

Browse files
tseaverdhermes
authored andcommitted
Suppress instance creation tests by default on CI (#3951)
* Fix 'populate_streaming' script after PR #3787. * Add utility for scrubbing orphaned instances. * Suppress instance creation tests by default on CI. Too many orphans, too little quota. * License header, formatting. Addresses: #3951 (comment) #3951 (comment).
1 parent 6ec260f commit 944e8fd

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

spanner/tests/system/test_system.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
from tests._fixtures import DDL_STATEMENTS
4747

4848

49-
IS_CIRCLE = os.getenv('CIRCLECI') == 'true'
50-
CREATE_INSTANCE = IS_CIRCLE or os.getenv(
49+
CREATE_INSTANCE = os.getenv(
5150
'GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE') is not None
5251

5352
if CREATE_INSTANCE:

spanner/tests/system/utils/populate_streaming.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def ensure_database(client):
8484
def populate_table(database, table_desc):
8585
all_ = KeySet(all_=True)
8686
columns = ('pkey', 'chunk_me')
87-
rows = list(database.execute_sql(
88-
'SELECT COUNT(*) FROM {}'.format(table_desc.table)))
87+
with database.snapshot() as snapshot:
88+
rows = list(snapshot.execute_sql(
89+
'SELECT COUNT(*) FROM {}'.format(table_desc.table)))
8990
assert len(rows) == 1
9091
count = rows[0][0]
9192
if count != table_desc.row_count:
@@ -102,8 +103,9 @@ def populate_table(database, table_desc):
102103
def populate_table_2_columns(database, table_desc):
103104
all_ = KeySet(all_=True)
104105
columns = ('pkey', 'chunk_me', 'chunk_me_2')
105-
rows = list(database.execute_sql(
106-
'SELECT COUNT(*) FROM {}'.format(table_desc.table)))
106+
with database.snapshot() as snapshot:
107+
rows = list(snapshot.execute_sql(
108+
'SELECT COUNT(*) FROM {}'.format(table_desc.table)))
107109
assert len(rows) == 1
108110
count = rows[0][0]
109111
if count != table_desc.row_count:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2017 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.cloud.spanner import Client
16+
from .streaming_utils import INSTANCE_NAME as STREAMING_INSTANCE
17+
18+
STANDARD_INSTANCE = 'google-cloud-python-systest'
19+
20+
21+
def scrub_instances(client):
22+
for instance in client.list_instances():
23+
if instance.name == STREAMING_INSTANCE:
24+
print('Not deleting streaming instance: {}'.format(
25+
STREAMING_INSTANCE))
26+
continue
27+
elif instance.name == STANDARD_INSTANCE:
28+
print('Not deleting standard instance: {}'.format(
29+
STANDARD_INSTANCE))
30+
else:
31+
print("deleting instance: {}".format(instance.name))
32+
instance.delete()
33+
34+
35+
if __name__ == '__main__':
36+
client = Client()
37+
scrub_instances(client)

0 commit comments

Comments
 (0)