1313
1414import os
1515
16- from gcp_devrel .testing import eventually_consistent
17- from flaky import flaky
16+ import backoff
1817from google .cloud import datastore
1918import pytest
2019
@@ -43,7 +42,7 @@ def client():
4342 client .cleanup ()
4443
4544
46- @flaky
45+ @pytest . mark . flaky
4746class TestDatastoreSnippets :
4847 # These tests mostly just test the absence of exceptions.
4948 def test_incomplete_key (self , client ):
@@ -106,19 +105,19 @@ def test_batch_lookup(self, client):
106105 def test_batch_delete (self , client ):
107106 snippets .batch_delete (client )
108107
109- @eventually_consistent . mark
108+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
110109 def test_unindexed_property_query (self , client ):
111110 tasks = snippets .unindexed_property_query (client )
112111 client .entities_to_delete .extend (tasks )
113112 assert tasks
114113
115- @eventually_consistent . mark
114+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
116115 def test_basic_query (self , client ):
117116 tasks = snippets .basic_query (client )
118117 client .entities_to_delete .extend (tasks )
119118 assert tasks
120119
121- @eventually_consistent . mark
120+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
122121 def test_projection_query (self , client ):
123122 priorities , percents = snippets .projection_query (client )
124123 client .entities_to_delete .extend (
@@ -139,59 +138,60 @@ def test_cursor_paging(self, client):
139138 client .entities_to_delete .append (
140139 snippets .insert (client ))
141140
142- @eventually_consistent . call
143- def _ ():
141+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
142+ def run_sample ():
144143 results = snippets .cursor_paging (client )
145144 page_one , cursor_one , page_two , cursor_two = results
146145
147146 assert len (page_one ) == 5
148147 assert len (page_two )
149148 assert cursor_one
149+ run_sample ()
150150
151- @eventually_consistent . mark
151+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
152152 def test_property_filter (self , client ):
153153 tasks = snippets .property_filter (client )
154154 client .entities_to_delete .extend (tasks )
155155 assert tasks
156156
157- @eventually_consistent . mark
157+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
158158 def test_composite_filter (self , client ):
159159 tasks = snippets .composite_filter (client )
160160 client .entities_to_delete .extend (tasks )
161161 assert tasks
162162
163- @eventually_consistent . mark
163+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
164164 def test_key_filter (self , client ):
165165 tasks = snippets .key_filter (client )
166166 client .entities_to_delete .extend (tasks )
167167 assert tasks
168168
169- @eventually_consistent . mark
169+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
170170 def test_ascending_sort (self , client ):
171171 tasks = snippets .ascending_sort (client )
172172 client .entities_to_delete .extend (tasks )
173173 assert tasks
174174
175- @eventually_consistent . mark
175+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
176176 def test_descending_sort (self , client ):
177177 tasks = snippets .descending_sort (client )
178178 client .entities_to_delete .extend (tasks )
179179 assert tasks
180180
181- @eventually_consistent . mark
181+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
182182 def test_multi_sort (self , client ):
183183 tasks = snippets .multi_sort (client )
184184 client .entities_to_delete .extend (tasks )
185185 assert tasks
186186
187- @eventually_consistent . mark
187+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
188188 def test_keys_only_query (self , client ):
189189 keys = snippets .keys_only_query (client )
190190 client .entities_to_delete .extend (
191191 client .query (kind = 'Task' ).fetch ())
192192 assert keys
193193
194- @eventually_consistent . mark
194+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
195195 def test_distinct_on_query (self , client ):
196196 tasks = snippets .distinct_on_query (client )
197197 client .entities_to_delete .extend (tasks )
@@ -246,37 +246,37 @@ def transactional_single_entity_group_read_only(self, client):
246246 assert task_list
247247 assert tasks_in_list
248248
249- @eventually_consistent . mark
249+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
250250 def test_namespace_run_query (self , client ):
251251 all_namespaces , filtered_namespaces = snippets .namespace_run_query (
252252 client )
253253 assert all_namespaces
254254 assert filtered_namespaces
255255 assert 'google' in filtered_namespaces
256256
257- @eventually_consistent . mark
257+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
258258 def test_kind_run_query (self , client ):
259259 kinds = snippets .kind_run_query (client )
260260 client .entities_to_delete .extend (
261261 client .query (kind = 'Task' ).fetch ())
262262 assert kinds
263263 assert 'Task' in kinds
264264
265- @eventually_consistent . mark
265+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
266266 def test_property_run_query (self , client ):
267267 kinds = snippets .property_run_query (client )
268268 client .entities_to_delete .extend (
269269 client .query (kind = 'Task' ).fetch ())
270270 assert kinds
271271 assert 'Task' in kinds
272272
273- @eventually_consistent . mark
273+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
274274 def test_property_by_kind_run_query (self , client ):
275275 reprs = snippets .property_by_kind_run_query (client )
276276 client .entities_to_delete .extend (
277277 client .query (kind = 'Task' ).fetch ())
278278 assert reprs
279279
280- @eventually_consistent . mark
280+ @backoff . on_exception ( backoff . expo , AssertionError , max_time = 120 )
281281 def test_index_merge_queries (self , client ):
282282 snippets .index_merge_queries (client )
0 commit comments