Skip to content

Commit 2d68a31

Browse files
Chris Rossitseaver
andauthored
test: fix flaky system test (#701)
Normally a unique namespace per test run is used to prevent different test runs from interfering with each other, but some tests are specifically for the default namespace. A discriminator is added to this test that allows us to narrow the test query to only entities created in the current test run. Fixes #700 Co-authored-by: Tres Seaver <tseaver@palladion.com>
1 parent 0a58cae commit 2d68a31

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/google-cloud-ndb/tests/system/test_query.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import datetime
2020
import functools
2121
import operator
22+
import uuid
2223

2324
import pytest
2425
import pytz
@@ -373,10 +374,12 @@ def test_query_default_namespace_when_context_namespace_is_other(
373374
374375
https://github.com/googleapis/python-ndb/issues/476
375376
"""
377+
unique_id = str(uuid.uuid4())
376378

377379
class SomeKind(ndb.Model):
378380
foo = ndb.IntegerProperty()
379381
bar = ndb.StringProperty()
382+
discriminator = ndb.StringProperty(default=unique_id)
380383

381384
entity1 = SomeKind(foo=1, bar="a", id="x", namespace=other_namespace)
382385
entity1.put()
@@ -389,7 +392,7 @@ class SomeKind(ndb.Model):
389392
eventually(SomeKind.query(namespace=other_namespace).fetch, length_equals(1))
390393

391394
with client_context.new(namespace=other_namespace).use():
392-
query = SomeKind.query(namespace="")
395+
query = SomeKind.query(namespace="").filter(SomeKind.discriminator == unique_id)
393396
results = eventually(query.fetch, length_equals(1))
394397

395398
assert results[0].foo == 2

0 commit comments

Comments
 (0)