Skip to content

Commit 59a8091

Browse files
author
Takashi Matsuo
authored
[bigtable] fix: wrap sample invocations with retries [(#3494)](GoogleCloudPlatform/python-docs-samples#3494)
fix #3070 Also added `BIGTABLE_INSTANCE` to testing/test-env.tmpl.sh
1 parent 43635d7 commit 59a8091

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
backoff==1.10.0
12
pytest==5.3.2

samples/snippets/writes/writes_test.py

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

19+
import backoff
20+
from google.api_core.exceptions import DeadlineExceeded
1921
from google.cloud import bigtable
2022

2123
from .write_batch import write_batch
@@ -55,22 +57,37 @@ def table_id(bigtable_instance):
5557

5658

5759
def test_writes(capsys, table_id):
58-
write_simple(PROJECT, BIGTABLE_INSTANCE, table_id)
5960

61+
# `row.commit()` sometimes ends up with DeadlineExceeded, so now
62+
# we put retries with a hard deadline.
63+
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
64+
def _write_simple():
65+
write_simple(PROJECT, BIGTABLE_INSTANCE, table_id)
66+
67+
_write_simple()
6068
out, _ = capsys.readouterr()
6169
assert 'Successfully wrote row' in out
6270

63-
write_increment(PROJECT, BIGTABLE_INSTANCE, table_id)
71+
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
72+
def _write_increment():
73+
write_increment(PROJECT, BIGTABLE_INSTANCE, table_id)
6474

75+
_write_increment()
6576
out, _ = capsys.readouterr()
6677
assert 'Successfully updated row' in out
6778

68-
write_conditional(PROJECT, BIGTABLE_INSTANCE, table_id)
79+
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
80+
def _write_conditional():
81+
write_conditional(PROJECT, BIGTABLE_INSTANCE, table_id)
6982

83+
_write_conditional()
7084
out, _ = capsys.readouterr()
7185
assert 'Successfully updated row\'s os_name' in out
7286

73-
write_batch(PROJECT, BIGTABLE_INSTANCE, table_id)
87+
@backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=60)
88+
def _write_batch():
89+
write_batch(PROJECT, BIGTABLE_INSTANCE, table_id)
7490

91+
_write_batch()
7592
out, _ = capsys.readouterr()
7693
assert 'Successfully wrote 2 rows' in out

0 commit comments

Comments
 (0)