Skip to content

Commit d8dd870

Browse files
author
Takashi Matsuo
authored
[datastore] fix: handle datastore eventual consistency (#3448)
* [datastore] fix: handle datastore eventual consistency fixes #2884 * fix flask_app_test too
1 parent fb9ef51 commit d8dd870

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

datastore/cloud-ndb/flask_app_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
import uuid
1616

17-
import pytest
1817

18+
import backoff
19+
import pytest
1920
from google.cloud import ndb
2021

2122
import flask_app
@@ -39,9 +40,13 @@ def test_index(test_book):
3940
flask_app.app.testing = True
4041
client = flask_app.app.test_client()
4142

42-
r = client.get('/')
43-
assert r.status_code == 200
44-
assert test_book.title in r.data.decode('utf-8')
43+
@backoff.on_exception(backoff.expo, AssertionError, max_time=60)
44+
def eventually_consistent_test():
45+
r = client.get('/')
46+
assert r.status_code == 200
47+
assert test_book.title in r.data.decode('utf-8')
48+
49+
eventually_consistent_test()
4550

4651

4752
def test_ndb_wsgi_middleware():

datastore/cloud-ndb/quickstart_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import uuid
1616

17+
import backoff
1718
import pytest
1819

1920
import quickstart
@@ -34,6 +35,10 @@ def test_book():
3435

3536

3637
def test_quickstart(capsys, test_book):
37-
quickstart.list_books()
38-
out, _ = capsys.readouterr()
39-
assert test_book.title in out
38+
@backoff.on_exception(backoff.expo, AssertionError, max_time=60)
39+
def eventually_consistent_test():
40+
quickstart.list_books()
41+
out, _ = capsys.readouterr()
42+
assert test_book.title in out
43+
44+
eventually_consistent_test()
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

0 commit comments

Comments
 (0)