From fcf05ed6ea0f99763e22a0298fd5b8d639eeb532 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Mon, 29 Jun 2020 19:27:22 +0000 Subject: [PATCH] fix(spanner): use uuid for unique id fixes #4197 (possibly) --- spanner/cloud-client/backup_sample_test.py | 12 ++++-------- spanner/cloud-client/snippets_test.py | 6 ++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/spanner/cloud-client/backup_sample_test.py b/spanner/cloud-client/backup_sample_test.py index 61c69a0be61..51822a9b5eb 100644 --- a/spanner/cloud-client/backup_sample_test.py +++ b/spanner/cloud-client/backup_sample_test.py @@ -11,8 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import random -import string +import uuid from google.cloud import spanner import pytest @@ -22,20 +21,17 @@ def unique_instance_id(): """ Creates a unique id for the database. """ - return 'test-instance-{}'.format(''.join(random.choice( - string.ascii_lowercase + string.digits) for _ in range(5))) + return f'test-instance-{uuid.uuid4().hex[:10]}' def unique_database_id(): """ Creates a unique id for the database. """ - return 'test-db-{}'.format(''.join(random.choice( - string.ascii_lowercase + string.digits) for _ in range(5))) + return f'test-db-{uuid.uuid4().hex[:10]}' def unique_backup_id(): """ Creates a unique id for the backup. """ - return 'test-backup-{}'.format(''.join(random.choice( - string.ascii_lowercase + string.digits) for _ in range(5))) + return f'test-backup-{uuid.uuid4().hex[:10]}' INSTANCE_ID = unique_instance_id() diff --git a/spanner/cloud-client/snippets_test.py b/spanner/cloud-client/snippets_test.py index 08d3e277d7f..a33c4424587 100644 --- a/spanner/cloud-client/snippets_test.py +++ b/spanner/cloud-client/snippets_test.py @@ -13,9 +13,8 @@ # limitations under the License. import os -import random -import string import time +import uuid from google.cloud import spanner import pytest @@ -25,8 +24,7 @@ def unique_database_id(): """ Creates a unique id for the database. """ - return 'test-db-{}'.format(''.join(random.choice( - string.ascii_lowercase + string.digits) for _ in range(5))) + return f'test-db-{uuid.uuid4().hex[:10]}' INSTANCE_ID = os.environ['SPANNER_INSTANCE']