Skip to content

Commit

Permalink
Adding Travis build ID to resource names in system tests.
Browse files Browse the repository at this point in the history
Fixes #1542.
  • Loading branch information
dhermes committed Apr 22, 2016
1 parent 8a7eea8 commit 71eeed9
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 85 deletions.
22 changes: 12 additions & 10 deletions system_tests/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
from gcloud.environment_vars import TESTS_PROJECT
from gcloud import bigquery

from system_test_utils import unique_resource_id

DATASET_NAME = 'system_tests_%012d' % (1000 * time.time(),)

DATASET_NAME = 'system_tests' + unique_resource_id()


class Config(object):
Expand Down Expand Up @@ -97,9 +99,9 @@ def test_update_dataset(self):

def test_list_datasets(self):
datasets_to_create = [
'new%d' % (1000 * time.time(),),
'newer%d' % (1000 * time.time(),),
'newest%d' % (1000 * time.time(),),
'new' + unique_resource_id(),
'newer' + unique_resource_id(),
'newest' + unique_resource_id(),
]
for dataset_name in datasets_to_create:
dataset = Config.CLIENT.dataset(dataset_name)
Expand Down Expand Up @@ -143,9 +145,9 @@ def test_list_tables(self):

# Insert some tables to be listed.
tables_to_create = [
'new%d' % (1000 * time.time(),),
'newer%d' % (1000 * time.time(),),
'newest%d' % (1000 * time.time(),),
'new' + unique_resource_id(),
'newer' + unique_resource_id(),
'newest' + unique_resource_id(),
]
full_name = bigquery.SchemaField('full_name', 'STRING',
mode='REQUIRED')
Expand Down Expand Up @@ -259,8 +261,8 @@ def test_load_table_from_storage_then_dump_table(self):
import csv
import tempfile
from gcloud.storage import Client as StorageClient
TIMESTAMP = 1000 * time.time()
BUCKET_NAME = 'bq_load_test_%d' % (TIMESTAMP,)
local_id = unique_resource_id()
BUCKET_NAME = 'bq_load_test_' + local_id
BLOB_NAME = 'person_ages.csv'
GS_URL = 'gs://%s/%s' % (BUCKET_NAME, BLOB_NAME)
ROWS = [
Expand Down Expand Up @@ -301,7 +303,7 @@ def test_load_table_from_storage_then_dump_table(self):
self.to_delete.insert(0, table)

job = Config.CLIENT.load_table_from_storage(
'bq_load_storage_test_%d' % (TIMESTAMP,), table, GS_URL)
'bq_load_storage_test_' + local_id, table, GS_URL)
job.create_disposition = 'CREATE_NEVER'
job.skip_leading_rows = 1
job.source_format = 'CSV'
Expand Down
7 changes: 4 additions & 3 deletions system_tests/bigtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
from gcloud.bigtable.row_data import PartialRowData
from gcloud.environment_vars import TESTS_PROJECT

from system_test_utils import unique_resource_id


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


def setUpModule():
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = Client(admin=True)
Config.CLUSTER = Config.CLIENT.cluster(CENTRAL_1C_ZONE, CLUSTER_ID,
display_name=CLUSTER_ID)
Expand Down
29 changes: 5 additions & 24 deletions system_tests/bigtable_happybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import operator
import struct
import time

import unittest2

Expand All @@ -24,13 +23,15 @@
from gcloud.bigtable.happybase.connection import Connection
from gcloud.environment_vars import TESTS_PROJECT

from bigtable import _operation_wait
from system_test_utils import unique_resource_id


_PACK_I64 = struct.Struct('>q').pack
_FIRST_ELT = operator.itemgetter(0)
_helpers.PROJECT = TESTS_PROJECT
ZONE = 'us-central1-c'
NOW_MILLIS = int(1000 * time.time())
CLUSTER_ID = 'gcloud-python-%d' % (NOW_MILLIS,)
CLUSTER_ID = 'gcloud-py' + unique_resource_id('-')
TABLE_NAME = 'table-name'
ALT_TABLE_NAME = 'other-table'
TTL_FOR_TEST = 3
Expand Down Expand Up @@ -61,26 +62,6 @@ class Config(object):
TABLE = None


def _operation_wait(operation, max_attempts=5):
"""Wait until an operation has completed.
:type operation: :class:`gcloud.bigtable.cluster.Operation`
:param operation: Operation that has not finished.
:type max_attempts: int
:param max_attempts: (Optional) The maximum number of times to check if
the operation has finished. Defaults to 5.
"""
total_sleep = 0
while not operation.finished():
if total_sleep > max_attempts:
return False
time.sleep(1)
total_sleep += 1

return True


def set_connection():
client = client_mod.Client(admin=True)
cluster = client.cluster(ZONE, CLUSTER_ID)
Expand Down Expand Up @@ -646,7 +627,7 @@ def test_put_with_timestamp(self):
value1 = 'value1'
value2 = 'value2'
row1_data = {COL1: value1, COL2: value2}
ts = NOW_MILLIS
ts = 1461367402

# Need to clean-up row1 after.
self.rows_to_delete.append(ROW_KEY1)
Expand Down
6 changes: 3 additions & 3 deletions system_tests/clear_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@


FETCH_MAX = 20
ALL_KINDS = [
ALL_KINDS = (
'Character',
'Company',
'Kind',
'Person',
'Post',
]
)
TRANSACTION_MAX_GROUPS = 5


Expand Down Expand Up @@ -98,7 +98,7 @@ def remove_all_entities(client=None):
if __name__ == '__main__':
print_func('This command will remove all entities for '
'the following kinds:')
print_func('\n'.join(['- ' + val for val in ALL_KINDS]))
print_func('\n'.join('- ' + val for val in ALL_KINDS))
response = six.moves.input('Is this OK [y/n]? ')
if response.lower() == 'y':
remove_all_entities()
Expand Down
7 changes: 3 additions & 4 deletions system_tests/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import datetime
import os
import time

import httplib2
import unittest2
Expand All @@ -26,11 +25,11 @@
from gcloud.environment_vars import GCD_DATASET
from gcloud.environment_vars import TESTS_PROJECT
from gcloud.exceptions import Conflict
# This assumes the command is being run via tox hence the
# repository root is the current directory.

import clear_datastore
import populate_datastore
from system_test_utils import EmulatorCreds
from system_test_utils import unique_resource_id


class Config(object):
Expand All @@ -54,7 +53,7 @@ def clone_client(client):
def setUpModule():
emulator_dataset = os.getenv(GCD_DATASET)
# Isolated namespace so concurrent test runs don't collide.
test_namespace = 'ns%d' % (1000 * time.time(),)
test_namespace = 'ns' + unique_resource_id()
if emulator_dataset is None:
_helpers.PROJECT = TESTS_PROJECT
Config.CLIENT = datastore.Client(namespace=test_namespace)
Expand Down
17 changes: 9 additions & 8 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
from gcloud.environment_vars import TESTS_PROJECT
from gcloud import logging

from system_test_utils import unique_resource_id

_MILLIS = 1000 * time.time()
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (_MILLIS,)
DEFAULT_SINK_NAME = 'system-tests-sink-%d' % (_MILLIS,)

_RESOURCE_ID = unique_resource_id('-')
DEFAULT_METRIC_NAME = 'system-tests-metric-%d' % (_RESOURCE_ID,)
DEFAULT_SINK_NAME = 'system-tests-sink-%d' % (_RESOURCE_ID,)
DEFAULT_FILTER = 'logName:syslog AND severity>=INFO'
DEFAULT_DESCRIPTION = 'System testing'
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
DATASET_NAME = 'system_testing_dataset_%d' % (_MILLIS,)
TOPIC_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_RESOURCE_ID,)
DATASET_NAME = 'system_testing_dataset_%d' % (_RESOURCE_ID,)
TOPIC_NAME = 'gcloud-python-system-testing-%d' % (_RESOURCE_ID,)


class Config(object):
Expand Down Expand Up @@ -66,8 +68,7 @@ def tearDown(self):

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

def test_log_text(self):
TEXT_PAYLOAD = 'System test: test_log_text'
Expand Down
8 changes: 4 additions & 4 deletions system_tests/populate_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ANCESTOR = ('Book', 'GoT')
RICKARD = ANCESTOR + ('Character', 'Rickard')
EDDARD = RICKARD + ('Character', 'Eddard')
KEY_PATHS = [
KEY_PATHS = (
RICKARD,
EDDARD,
ANCESTOR + ('Character', 'Catelyn'),
Expand All @@ -37,8 +37,8 @@
EDDARD + ('Character', 'Robb'),
EDDARD + ('Character', 'Bran'),
EDDARD + ('Character', 'Jon Snow'),
]
CHARACTERS = [
)
CHARACTERS = (
{
'name': u'Rickard',
'family': u'Stark',
Expand Down Expand Up @@ -80,7 +80,7 @@
'appearances': 32,
'alive': True,
},
]
)


def print_func(message):
Expand Down
34 changes: 18 additions & 16 deletions system_tests/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
from gcloud.environment_vars import PUBSUB_EMULATOR
from gcloud.environment_vars import TESTS_PROJECT
from gcloud import pubsub

from system_test_utils import EmulatorCreds
from system_test_utils import unique_resource_id


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


class Config(object):
Expand Down Expand Up @@ -58,7 +60,7 @@ def tearDown(self):
doomed.delete()

def test_create_topic(self):
topic_name = 'a-new-topic%d' % (1000 * time.time(),)
topic_name = 'a-new-topic' + unique_resource_id()
topic = Config.CLIENT.topic(topic_name)
self.assertFalse(topic.exists())
topic.create()
Expand All @@ -68,9 +70,9 @@ def test_create_topic(self):

def test_list_topics(self):
topics_to_create = [
'new%d' % (1000 * time.time(),),
'newer%d' % (1000 * time.time(),),
'newest%d' % (1000 * time.time(),),
'new' + unique_resource_id(),
'newer' + unique_resource_id(),
'newest' + unique_resource_id(),
]
for topic_name in topics_to_create:
topic = Config.CLIENT.topic(topic_name)
Expand All @@ -89,7 +91,7 @@ def test_create_subscription_defaults(self):
self.assertFalse(topic.exists())
topic.create()
self.to_delete.append(topic)
SUBSCRIPTION_NAME = 'subscribing-now-%d' % (1000 * time.time(),)
SUBSCRIPTION_NAME = 'subscribing-now-' + unique_resource_id()
subscription = topic.subscription(SUBSCRIPTION_NAME)
self.assertFalse(subscription.exists())
subscription.create()
Expand All @@ -103,7 +105,7 @@ def test_create_subscription_w_ack_deadline(self):
self.assertFalse(topic.exists())
topic.create()
self.to_delete.append(topic)
SUBSCRIPTION_NAME = 'subscribing-now-%d' % (1000 * time.time(),)
SUBSCRIPTION_NAME = 'subscribing-now-' + unique_resource_id()
subscription = topic.subscription(SUBSCRIPTION_NAME, ack_deadline=120)
self.assertFalse(subscription.exists())
subscription.create()
Expand All @@ -121,9 +123,9 @@ def test_list_subscriptions(self):
empty, _ = topic.list_subscriptions()
self.assertEqual(len(empty), 0)
subscriptions_to_create = [
'new%d' % (1000 * time.time(),),
'newer%d' % (1000 * time.time(),),
'newest%d' % (1000 * time.time(),),
'new' + unique_resource_id(),
'newer' + unique_resource_id(),
'newest' + unique_resource_id(),
]
for subscription_name in subscriptions_to_create:
subscription = topic.subscription(subscription_name)
Expand All @@ -142,7 +144,7 @@ def test_message_pull_mode_e2e(self):
self.assertFalse(topic.exists())
topic.create()
self.to_delete.append(topic)
SUBSCRIPTION_NAME = 'subscribing-now-%d' % (1000 * time.time(),)
SUBSCRIPTION_NAME = 'subscribing-now-' + unique_resource_id()
subscription = topic.subscription(SUBSCRIPTION_NAME)
self.assertFalse(subscription.exists())
subscription.create()
Expand Down Expand Up @@ -170,7 +172,7 @@ def _by_timestamp(message):
self.assertEqual(message2.attributes['extra'], EXTRA_2)

def test_topic_iam_policy(self):
topic_name = 'test-topic-iam-policy-topic-%d' % (1000 * time.time(),)
topic_name = 'test-topic-iam-policy-topic-' + unique_resource_id()
topic = Config.CLIENT.topic(topic_name)
topic.create()
count = 5
Expand All @@ -185,7 +187,7 @@ def test_topic_iam_policy(self):
self.assertEqual(new_policy.viewers, policy.viewers)

def test_subscription_iam_policy(self):
topic_name = 'test-sub-iam-policy-topic-%d' % (1000 * time.time(),)
topic_name = 'test-sub-iam-policy-topic-' + unique_resource_id()
topic = Config.CLIENT.topic(topic_name)
topic.create()
count = 5
Expand All @@ -194,7 +196,7 @@ def test_subscription_iam_policy(self):
count -= 1
self.assertTrue(topic.exists())
self.to_delete.append(topic)
SUB_NAME = 'test-sub-iam-policy-sub-%d' % (1000 * time.time(),)
SUB_NAME = 'test-sub-iam-policy-sub-' + unique_resource_id()
subscription = topic.subscription(SUB_NAME)
subscription.create()
count = 5
Expand All @@ -209,8 +211,8 @@ def test_subscription_iam_policy(self):
self.assertEqual(new_policy.viewers, policy.viewers)

def test_fetch_delete_subscription_w_deleted_topic(self):
TO_DELETE = 'delete-me-%d' % (1000 * time.time(),)
ORPHANED = 'orphaned-%d' % (1000 * time.time(),)
TO_DELETE = 'delete-me-' + unique_resource_id()
ORPHANED = 'orphaned-' + unique_resource_id()
topic = Config.CLIENT.topic(TO_DELETE)
topic.create()
subscription = topic.subscription(ORPHANED)
Expand Down
4 changes: 2 additions & 2 deletions system_tests/run_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_start_command(package):
:rtype: tuple
:returns: The arguments to be used, in a tuple.
"""
return ('gcloud', 'beta', 'emulators', package, 'start')
return 'gcloud', 'beta', 'emulators', package, 'start'


def get_env_init_command(package):
Expand All @@ -74,7 +74,7 @@ def get_env_init_command(package):
:rtype: tuple
:returns: The arguments to be used, in a tuple.
"""
return ('gcloud', 'beta', 'emulators', package, 'env-init')
return 'gcloud', 'beta', 'emulators', package, 'env-init'


def datastore_wait_ready(popen):
Expand Down
Loading

0 comments on commit 71eeed9

Please sign in to comment.