Skip to content

Commit

Permalink
fix(spanner): use uuid for unique id (#4198)
Browse files Browse the repository at this point in the history
fixes #4197
(possibly)
  • Loading branch information
Takashi Matsuo authored Jun 29, 2020
1 parent e27ab34 commit 32f6dcc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 4 additions & 8 deletions spanner/cloud-client/backup_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions spanner/cloud-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down

0 comments on commit 32f6dcc

Please sign in to comment.