Skip to content

Commit

Permalink
test: fix flaky system test
Browse files Browse the repository at this point in the history
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 naorrow the test query to only entities created
in the current test run.

Fixes googleapis#700
  • Loading branch information
Chris Rossi committed Jul 29, 2021
1 parent cf10a14 commit 6841725
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/system/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class SomeKind(ndb.Model):


def test_query_default_namespace_when_context_namespace_is_other(
client_context, dispose_of, other_namespace
client_context, dispose_of, namespace, other_namespace
):
"""Regression test for #476.
Expand All @@ -377,6 +377,7 @@ def test_query_default_namespace_when_context_namespace_is_other(
class SomeKind(ndb.Model):
foo = ndb.IntegerProperty()
bar = ndb.StringProperty()
discriminator = ndb.StringProperty(default=namespace)

entity1 = SomeKind(foo=1, bar="a", id="x", namespace=other_namespace)
entity1.put()
Expand All @@ -389,7 +390,7 @@ class SomeKind(ndb.Model):
eventually(SomeKind.query(namespace=other_namespace).fetch, length_equals(1))

with client_context.new(namespace=other_namespace).use():
query = SomeKind.query(namespace="")
query = SomeKind.query(namespace="").filter(SomeKind.discriminator == namespace)
results = eventually(query.fetch, length_equals(1))

assert results[0].foo == 2
Expand Down

0 comments on commit 6841725

Please sign in to comment.