Skip to content

Commit

Permalink
racetest: Switch to using Zope interfaces for model specification
Browse files Browse the repository at this point in the history
Suggested by @d-maurer: #368 (review)
  • Loading branch information
navytux committed Aug 31, 2022
1 parent a94d63c commit 1ccb7fc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ZODB/tests/racetest.py
Expand Up @@ -46,12 +46,13 @@
from ZODB.utils import tid_repr, at2before
from ZODB.tests.MinPO import MinPO
from ZODB.tests.util import with_high_concurrency, long_test
from zope.interface import Interface, implementer

import threading
from random import randint


class ISpec:
class ISpec(Interface):
"""ISpec interface represents testing specification used by check_race_*"""

def init(root):
Expand All @@ -68,7 +69,8 @@ def assertStateOK(root):
"""


class T2ObjectsInc(ISpec):
@implementer(ISpec)
class T2ObjectsInc:
"""T2ObjectsInc is specification with behaviour where two objects obj1
and obj2 are incremented synchronously.
Expand All @@ -93,7 +95,8 @@ def assertStateOK(_, root):
raise AssertionError("obj1 (%d) != obj2 (%d)" % (i1, i2))


class T2ObjectsInc2Phase(ISpec):
@implementer(ISpec)
class T2ObjectsInc2Phase:
"""T2ObjectsInc2Phase is specification with behaviour where two objects
obj1 and obj2 are incremented in lock-step.
Expand Down Expand Up @@ -137,7 +140,7 @@ def check_race_loadopen_vs_local_invalidate(self):

@with_high_concurrency
def _check_race_loadopen_vs_local_invalidate(self, spec):
assert isinstance(spec, ISpec)
assert ISpec.providedBy(spec)
db = DB(self._storage)

# init initializes the database according to the spec.
Expand Down Expand Up @@ -249,7 +252,7 @@ def check_race_load_vs_external_invalidate(self):

@with_high_concurrency
def _check_race_load_vs_external_invalidate(self, spec):
assert isinstance(spec, ISpec)
assert ISpec.providedBy(spec)

# init initializes the database according to the spec.
def init():
Expand Down Expand Up @@ -359,7 +362,7 @@ def check_race_external_invalidate_vs_disconnect(self):

@with_high_concurrency
def _check_race_xxx_vs_external_disconnect(self, spec):
assert isinstance(spec, ISpec)
assert ISpec.providedBy(spec)

# init initializes the database according to the spec.
def init():
Expand Down

0 comments on commit 1ccb7fc

Please sign in to comment.