Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 2841442

Browse files
authored
chore(samples): harden 'tableadmin' samples against 429/503 errors (#418)
Closes #417.
1 parent 4d392b2 commit 2841442

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest==6.2.4
2+
google-cloud-testutils==1.0.0

samples/tableadmin/tableadmin_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import os
1717
import uuid
1818

19+
from google.api_core import exceptions
20+
from test_utils.retry import RetryErrors
21+
1922
from tableadmin import create_table
2023
from tableadmin import delete_table
2124
from tableadmin import run_table_operations
@@ -24,11 +27,13 @@
2427
BIGTABLE_INSTANCE = os.environ['BIGTABLE_INSTANCE']
2528
TABLE_ID_FORMAT = 'tableadmin-test-{}'
2629

30+
retry_429_503 = RetryErrors(exceptions.TooManyRequests, exceptions.ServiceUnavailable)
31+
2732

2833
def test_run_table_operations(capsys):
2934
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
3035

31-
run_table_operations(PROJECT, BIGTABLE_INSTANCE, table_id)
36+
retry_429_503(run_table_operations)(PROJECT, BIGTABLE_INSTANCE, table_id)
3237
out, _ = capsys.readouterr()
3338

3439
assert 'Creating the ' + table_id + ' table.' in out
@@ -48,14 +53,14 @@ def test_run_table_operations(capsys):
4853
assert 'Delete a column family cf2...' in out
4954
assert 'Column family cf2 deleted successfully.' in out
5055

51-
delete_table(PROJECT, BIGTABLE_INSTANCE, table_id)
56+
retry_429_503(delete_table)(PROJECT, BIGTABLE_INSTANCE, table_id)
5257

5358

5459
def test_delete_table(capsys):
5560
table_id = TABLE_ID_FORMAT.format(uuid.uuid4().hex[:8])
56-
create_table(PROJECT, BIGTABLE_INSTANCE, table_id)
61+
retry_429_503(create_table)(PROJECT, BIGTABLE_INSTANCE, table_id)
5762

58-
delete_table(PROJECT, BIGTABLE_INSTANCE, table_id)
63+
retry_429_503(delete_table)(PROJECT, BIGTABLE_INSTANCE, table_id)
5964
out, _ = capsys.readouterr()
6065

6166
assert 'Table ' + table_id + ' exists.' in out

0 commit comments

Comments
 (0)