Skip to content

Commit

Permalink
[datastore] fix: handle datastore eventual consistency (#3448)
Browse files Browse the repository at this point in the history
* [datastore] fix: handle datastore eventual consistency

fixes #2884

* fix flask_app_test too
  • Loading branch information
Takashi Matsuo committed Apr 21, 2020
1 parent fb9ef51 commit d8dd870
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
13 changes: 9 additions & 4 deletions datastore/cloud-ndb/flask_app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

import uuid

import pytest

import backoff
import pytest
from google.cloud import ndb

import flask_app
Expand All @@ -39,9 +40,13 @@ def test_index(test_book):
flask_app.app.testing = True
client = flask_app.app.test_client()

r = client.get('/')
assert r.status_code == 200
assert test_book.title in r.data.decode('utf-8')
@backoff.on_exception(backoff.expo, AssertionError, max_time=60)
def eventually_consistent_test():
r = client.get('/')
assert r.status_code == 200
assert test_book.title in r.data.decode('utf-8')

eventually_consistent_test()


def test_ndb_wsgi_middleware():
Expand Down
11 changes: 8 additions & 3 deletions datastore/cloud-ndb/quickstart_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import uuid

import backoff
import pytest

import quickstart
Expand All @@ -34,6 +35,10 @@ def test_book():


def test_quickstart(capsys, test_book):
quickstart.list_books()
out, _ = capsys.readouterr()
assert test_book.title in out
@backoff.on_exception(backoff.expo, AssertionError, max_time=60)
def eventually_consistent_test():
quickstart.list_books()
out, _ = capsys.readouterr()
assert test_book.title in out

eventually_consistent_test()
1 change: 1 addition & 0 deletions datastore/cloud-ndb/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
backoff==1.10.0
pytest==5.3.2

0 comments on commit d8dd870

Please sign in to comment.