Skip to content

Commit

Permalink
test: refactor concurrency test using orchestrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rossi committed Aug 16, 2021
1 parent 6b48548 commit 9df9196
Show file tree
Hide file tree
Showing 5 changed files with 617 additions and 126 deletions.
9 changes: 9 additions & 0 deletions google/cloud/ndb/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
log = logging.getLogger(__name__)


def _syncpoint_692():
"""A no-op function meant to be patched for testing.
Should be replaced by `orchestrate.syncpoint` using `mock.patch` during testing to
orchestrate concurrent testing scenarios.
"""


class ContextCache(dict):
"""A per-context in-memory entity cache.
Expand Down Expand Up @@ -684,6 +692,7 @@ def _update_key(key, new_value):

value = new_value(old_value)
utils.logging_debug(log, "new value: {}", value)
_syncpoint_692()

if old_value is not None:
utils.logging_debug(log, "compare and swap")
Expand Down
35 changes: 22 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,31 @@ def initialize_environment(request, environ):


@pytest.fixture
def context():
client = mock.Mock(
project="testing",
namespace=None,
spec=("project", "namespace"),
stub=mock.Mock(spec=()),
)
context = context_module.Context(
client,
eventloop=TestingEventLoop(),
datastore_policy=True,
legacy_data=False,
)
def context_factory():
def context(**kwargs):
client = mock.Mock(
project="testing",
namespace=None,
spec=("project", "namespace"),
stub=mock.Mock(spec=()),
)
context = context_module.Context(
client,
eventloop=TestingEventLoop(),
datastore_policy=True,
legacy_data=False,
**kwargs,
)
return context

return context


@pytest.fixture
def context(context_factory):
return context_factory()


@pytest.fixture
def in_context(context):
assert not context_module._state.context
Expand Down
Loading

0 comments on commit 9df9196

Please sign in to comment.