Skip to content

Commit 53d8a5b

Browse files
committed
Adding Travis build ID to resource names in system tests.
Fixes #1542.
1 parent d857d20 commit 53d8a5b

12 files changed

+85
-85
lines changed

system_tests/bigquery.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
from gcloud.environment_vars import TESTS_PROJECT
2222
from gcloud import bigquery
2323

24+
from system_test_utils import unique_resource_id
2425

25-
DATASET_NAME = 'system_tests_%012d' % (1000 * time.time(),)
26+
27+
DATASET_NAME = 'system_tests' + unique_resource_id()
2628

2729

2830
class Config(object):
@@ -97,9 +99,9 @@ def test_update_dataset(self):
9799

98100
def test_list_datasets(self):
99101
datasets_to_create = [
100-
'new%d' % (1000 * time.time(),),
101-
'newer%d' % (1000 * time.time(),),
102-
'newest%d' % (1000 * time.time(),),
102+
'new' + unique_resource_id(),
103+
'newer' + unique_resource_id(),
104+
'newest' + unique_resource_id(),
103105
]
104106
for dataset_name in datasets_to_create:
105107
dataset = Config.CLIENT.dataset(dataset_name)
@@ -143,9 +145,9 @@ def test_list_tables(self):
143145

144146
# Insert some tables to be listed.
145147
tables_to_create = [
146-
'new%d' % (1000 * time.time(),),
147-
'newer%d' % (1000 * time.time(),),
148-
'newest%d' % (1000 * time.time(),),
148+
'new' + unique_resource_id(),
149+
'newer' + unique_resource_id(),
150+
'newest' + unique_resource_id(),
149151
]
150152
full_name = bigquery.SchemaField('full_name', 'STRING',
151153
mode='REQUIRED')
@@ -259,8 +261,8 @@ def test_load_table_from_storage_then_dump_table(self):
259261
import csv
260262
import tempfile
261263
from gcloud.storage import Client as StorageClient
262-
TIMESTAMP = 1000 * time.time()
263-
BUCKET_NAME = 'bq_load_test_%d' % (TIMESTAMP,)
264+
local_id = unique_resource_id()
265+
BUCKET_NAME = 'bq_load_test' + local_id
264266
BLOB_NAME = 'person_ages.csv'
265267
GS_URL = 'gs://%s/%s' % (BUCKET_NAME, BLOB_NAME)
266268
ROWS = [
@@ -301,7 +303,7 @@ def test_load_table_from_storage_then_dump_table(self):
301303
self.to_delete.insert(0, table)
302304

303305
job = Config.CLIENT.load_table_from_storage(
304-
'bq_load_storage_test_%d' % (TIMESTAMP,), table, GS_URL)
306+
'bq_load_storage_test_' + local_id, table, GS_URL)
305307
job.create_disposition = 'CREATE_NEVER'
306308
job.skip_leading_rows = 1
307309
job.source_format = 'CSV'

system_tests/bigtable.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
from gcloud.bigtable.row_data import PartialRowData
3333
from gcloud.environment_vars import TESTS_PROJECT
3434

35+
from system_test_utils import unique_resource_id
36+
3537

36-
_helpers.PROJECT = TESTS_PROJECT
3738
CENTRAL_1C_ZONE = 'us-central1-c'
38-
NOW_MILLIS = int(1000 * time.time())
39-
CLUSTER_ID = 'gcloud-python-%d' % (NOW_MILLIS,)
39+
CLUSTER_ID = 'gcloud-py' + unique_resource_id('-')
4040
TABLE_ID = 'gcloud-python-test-table'
4141
COLUMN_FAMILY_ID1 = u'col-fam-id1'
4242
COLUMN_FAMILY_ID2 = u'col-fam-id2'
@@ -89,6 +89,7 @@ def _operation_wait(operation, max_attempts=5):
8989

9090

9191
def setUpModule():
92+
_helpers.PROJECT = TESTS_PROJECT
9293
Config.CLIENT = Client(admin=True)
9394
Config.CLUSTER = Config.CLIENT.cluster(CENTRAL_1C_ZONE, CLUSTER_ID,
9495
display_name=CLUSTER_ID)

system_tests/bigtable_happybase.py

+5-24
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import operator
1717
import struct
18-
import time
1918

2019
import unittest2
2120

@@ -24,13 +23,15 @@
2423
from gcloud.bigtable.happybase.connection import Connection
2524
from gcloud.environment_vars import TESTS_PROJECT
2625

26+
from bigtable import _operation_wait
27+
from system_test_utils import unique_resource_id
28+
2729

2830
_PACK_I64 = struct.Struct('>q').pack
2931
_FIRST_ELT = operator.itemgetter(0)
3032
_helpers.PROJECT = TESTS_PROJECT
3133
ZONE = 'us-central1-c'
32-
NOW_MILLIS = int(1000 * time.time())
33-
CLUSTER_ID = 'gcloud-python-%d' % (NOW_MILLIS,)
34+
CLUSTER_ID = 'gcloud-py' + unique_resource_id('-')
3435
TABLE_NAME = 'table-name'
3536
ALT_TABLE_NAME = 'other-table'
3637
TTL_FOR_TEST = 3
@@ -61,26 +62,6 @@ class Config(object):
6162
TABLE = None
6263

6364

64-
def _operation_wait(operation, max_attempts=5):
65-
"""Wait until an operation has completed.
66-
67-
:type operation: :class:`gcloud.bigtable.cluster.Operation`
68-
:param operation: Operation that has not finished.
69-
70-
:type max_attempts: int
71-
:param max_attempts: (Optional) The maximum number of times to check if
72-
the operation has finished. Defaults to 5.
73-
"""
74-
total_sleep = 0
75-
while not operation.finished():
76-
if total_sleep > max_attempts:
77-
return False
78-
time.sleep(1)
79-
total_sleep += 1
80-
81-
return True
82-
83-
8465
def set_connection():
8566
client = client_mod.Client(admin=True)
8667
cluster = client.cluster(ZONE, CLUSTER_ID)
@@ -646,7 +627,7 @@ def test_put_with_timestamp(self):
646627
value1 = 'value1'
647628
value2 = 'value2'
648629
row1_data = {COL1: value1, COL2: value2}
649-
ts = NOW_MILLIS
630+
ts = 1461367402
650631

651632
# Need to clean-up row1 after.
652633
self.rows_to_delete.append(ROW_KEY1)

system_tests/clear_datastore.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626

2727
FETCH_MAX = 20
28-
ALL_KINDS = [
28+
ALL_KINDS = (
2929
'Character',
3030
'Company',
3131
'Kind',
3232
'Person',
3333
'Post',
34-
]
34+
)
3535
TRANSACTION_MAX_GROUPS = 5
3636

3737

@@ -98,7 +98,7 @@ def remove_all_entities(client=None):
9898
if __name__ == '__main__':
9999
print_func('This command will remove all entities for '
100100
'the following kinds:')
101-
print_func('\n'.join(['- ' + val for val in ALL_KINDS]))
101+
print_func('\n'.join('- ' + val for val in ALL_KINDS))
102102
response = six.moves.input('Is this OK [y/n]? ')
103103
if response.lower() == 'y':
104104
remove_all_entities()

system_tests/datastore.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import datetime
1616
import os
17-
import time
1817

1918
import httplib2
2019
import unittest2
@@ -26,11 +25,11 @@
2625
from gcloud.environment_vars import GCD_DATASET
2726
from gcloud.environment_vars import TESTS_PROJECT
2827
from gcloud.exceptions import Conflict
29-
# This assumes the command is being run via tox hence the
30-
# repository root is the current directory.
28+
3129
import clear_datastore
3230
import populate_datastore
3331
from system_test_utils import EmulatorCreds
32+
from system_test_utils import unique_resource_id
3433

3534

3635
class Config(object):
@@ -54,7 +53,7 @@ def clone_client(client):
5453
def setUpModule():
5554
emulator_dataset = os.getenv(GCD_DATASET)
5655
# Isolated namespace so concurrent test runs don't collide.
57-
test_namespace = 'ns%d' % (1000 * time.time(),)
56+
test_namespace = 'ns' + unique_resource_id()
5857
if emulator_dataset is None:
5958
_helpers.PROJECT = TESTS_PROJECT
6059
Config.CLIENT = datastore.Client(namespace=test_namespace)

system_tests/logging_.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
from gcloud.environment_vars import TESTS_PROJECT
2121
from gcloud import logging
2222

23+
from system_test_utils import unique_resource_id
2324

24-
_MILLIS = 1000 * time.time()
25-
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (_MILLIS,)
26-
DEFAULT_SINK_NAME = 'system-tests-sink-%d' % (_MILLIS,)
25+
26+
_RESOURCE_ID = unique_resource_id('-')
27+
DEFAULT_METRIC_NAME = 'system-tests-metric%s' % (_RESOURCE_ID,)
28+
DEFAULT_SINK_NAME = 'system-tests-sink%s' % (_RESOURCE_ID,)
2729
DEFAULT_FILTER = 'logName:syslog AND severity>=INFO'
2830
DEFAULT_DESCRIPTION = 'System testing'
29-
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
30-
DATASET_NAME = 'system_testing_dataset_%d' % (_MILLIS,)
31-
TOPIC_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
31+
BUCKET_NAME = 'gcloud-python-system-testing%s' % (_RESOURCE_ID,)
32+
DATASET_NAME = ('system_testing_dataset' + _RESOURCE_ID).replace('-', '_')
33+
TOPIC_NAME = 'gcloud-python-system-testing%s' % (_RESOURCE_ID,)
3234

3335

3436
class Config(object):
@@ -66,8 +68,7 @@ def tearDown(self):
6668

6769
@staticmethod
6870
def _logger_name():
69-
_millis = 1000 * time.time()
70-
return 'system-tests-logger-%d' % (_millis,)
71+
return 'system-tests-logger' + unique_resource_id('-')
7172

7273
def test_log_text(self):
7374
TEXT_PAYLOAD = 'System test: test_log_text'

system_tests/populate_datastore.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
ANCESTOR = ('Book', 'GoT')
2929
RICKARD = ANCESTOR + ('Character', 'Rickard')
3030
EDDARD = RICKARD + ('Character', 'Eddard')
31-
KEY_PATHS = [
31+
KEY_PATHS = (
3232
RICKARD,
3333
EDDARD,
3434
ANCESTOR + ('Character', 'Catelyn'),
@@ -37,8 +37,8 @@
3737
EDDARD + ('Character', 'Robb'),
3838
EDDARD + ('Character', 'Bran'),
3939
EDDARD + ('Character', 'Jon Snow'),
40-
]
41-
CHARACTERS = [
40+
)
41+
CHARACTERS = (
4242
{
4343
'name': u'Rickard',
4444
'family': u'Stark',
@@ -80,7 +80,7 @@
8080
'appearances': 32,
8181
'alive': True,
8282
},
83-
]
83+
)
8484

8585

8686
def print_func(message):

system_tests/pubsub.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
from gcloud.environment_vars import PUBSUB_EMULATOR
2323
from gcloud.environment_vars import TESTS_PROJECT
2424
from gcloud import pubsub
25+
2526
from system_test_utils import EmulatorCreds
27+
from system_test_utils import unique_resource_id
2628

2729

28-
DEFAULT_TOPIC_NAME = 'subscribe-me%d' % (1000 * time.time(),)
30+
DEFAULT_TOPIC_NAME = 'subscribe-me' + unique_resource_id('-')
2931

3032

3133
class Config(object):
@@ -58,7 +60,7 @@ def tearDown(self):
5860
doomed.delete()
5961

6062
def test_create_topic(self):
61-
topic_name = 'a-new-topic%d' % (1000 * time.time(),)
63+
topic_name = 'a-new-topic' + unique_resource_id('-')
6264
topic = Config.CLIENT.topic(topic_name)
6365
self.assertFalse(topic.exists())
6466
topic.create()
@@ -68,9 +70,9 @@ def test_create_topic(self):
6870

6971
def test_list_topics(self):
7072
topics_to_create = [
71-
'new%d' % (1000 * time.time(),),
72-
'newer%d' % (1000 * time.time(),),
73-
'newest%d' % (1000 * time.time(),),
73+
'new' + unique_resource_id(),
74+
'newer' + unique_resource_id(),
75+
'newest' + unique_resource_id(),
7476
]
7577
for topic_name in topics_to_create:
7678
topic = Config.CLIENT.topic(topic_name)
@@ -89,7 +91,7 @@ def test_create_subscription_defaults(self):
8991
self.assertFalse(topic.exists())
9092
topic.create()
9193
self.to_delete.append(topic)
92-
SUBSCRIPTION_NAME = 'subscribing-now-%d' % (1000 * time.time(),)
94+
SUBSCRIPTION_NAME = 'subscribing-now' + unique_resource_id('-')
9395
subscription = topic.subscription(SUBSCRIPTION_NAME)
9496
self.assertFalse(subscription.exists())
9597
subscription.create()
@@ -103,7 +105,7 @@ def test_create_subscription_w_ack_deadline(self):
103105
self.assertFalse(topic.exists())
104106
topic.create()
105107
self.to_delete.append(topic)
106-
SUBSCRIPTION_NAME = 'subscribing-now-%d' % (1000 * time.time(),)
108+
SUBSCRIPTION_NAME = 'subscribing-now' + unique_resource_id()
107109
subscription = topic.subscription(SUBSCRIPTION_NAME, ack_deadline=120)
108110
self.assertFalse(subscription.exists())
109111
subscription.create()
@@ -121,9 +123,9 @@ def test_list_subscriptions(self):
121123
empty, _ = topic.list_subscriptions()
122124
self.assertEqual(len(empty), 0)
123125
subscriptions_to_create = [
124-
'new%d' % (1000 * time.time(),),
125-
'newer%d' % (1000 * time.time(),),
126-
'newest%d' % (1000 * time.time(),),
126+
'new' + unique_resource_id(),
127+
'newer' + unique_resource_id(),
128+
'newest' + unique_resource_id(),
127129
]
128130
for subscription_name in subscriptions_to_create:
129131
subscription = topic.subscription(subscription_name)
@@ -142,7 +144,7 @@ def test_message_pull_mode_e2e(self):
142144
self.assertFalse(topic.exists())
143145
topic.create()
144146
self.to_delete.append(topic)
145-
SUBSCRIPTION_NAME = 'subscribing-now-%d' % (1000 * time.time(),)
147+
SUBSCRIPTION_NAME = 'subscribing-now' + unique_resource_id('-')
146148
subscription = topic.subscription(SUBSCRIPTION_NAME)
147149
self.assertFalse(subscription.exists())
148150
subscription.create()
@@ -170,7 +172,7 @@ def _by_timestamp(message):
170172
self.assertEqual(message2.attributes['extra'], EXTRA_2)
171173

172174
def test_topic_iam_policy(self):
173-
topic_name = 'test-topic-iam-policy-topic-%d' % (1000 * time.time(),)
175+
topic_name = 'test-topic-iam-policy-topic' + unique_resource_id('-')
174176
topic = Config.CLIENT.topic(topic_name)
175177
topic.create()
176178
count = 5
@@ -185,7 +187,7 @@ def test_topic_iam_policy(self):
185187
self.assertEqual(new_policy.viewers, policy.viewers)
186188

187189
def test_subscription_iam_policy(self):
188-
topic_name = 'test-sub-iam-policy-topic-%d' % (1000 * time.time(),)
190+
topic_name = 'test-sub-iam-policy-topic' + unique_resource_id('-')
189191
topic = Config.CLIENT.topic(topic_name)
190192
topic.create()
191193
count = 5
@@ -194,7 +196,7 @@ def test_subscription_iam_policy(self):
194196
count -= 1
195197
self.assertTrue(topic.exists())
196198
self.to_delete.append(topic)
197-
SUB_NAME = 'test-sub-iam-policy-sub-%d' % (1000 * time.time(),)
199+
SUB_NAME = 'test-sub-iam-policy-sub' + unique_resource_id('-')
198200
subscription = topic.subscription(SUB_NAME)
199201
subscription.create()
200202
count = 5
@@ -209,8 +211,8 @@ def test_subscription_iam_policy(self):
209211
self.assertEqual(new_policy.viewers, policy.viewers)
210212

211213
def test_fetch_delete_subscription_w_deleted_topic(self):
212-
TO_DELETE = 'delete-me-%d' % (1000 * time.time(),)
213-
ORPHANED = 'orphaned-%d' % (1000 * time.time(),)
214+
TO_DELETE = 'delete-me' + unique_resource_id('-')
215+
ORPHANED = 'orphaned' + unique_resource_id('-')
214216
topic = Config.CLIENT.topic(TO_DELETE)
215217
topic.create()
216218
subscription = topic.subscription(ORPHANED)

system_tests/run_emulator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_start_command(package):
6262
:rtype: tuple
6363
:returns: The arguments to be used, in a tuple.
6464
"""
65-
return ('gcloud', 'beta', 'emulators', package, 'start')
65+
return 'gcloud', 'beta', 'emulators', package, 'start'
6666

6767

6868
def get_env_init_command(package):
@@ -74,7 +74,7 @@ def get_env_init_command(package):
7474
:rtype: tuple
7575
:returns: The arguments to be used, in a tuple.
7676
"""
77-
return ('gcloud', 'beta', 'emulators', package, 'env-init')
77+
return 'gcloud', 'beta', 'emulators', package, 'env-init'
7878

7979

8080
def datastore_wait_ready(popen):

0 commit comments

Comments
 (0)