Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EDGEDB_TEST_REPEATS env var for testing function cache #7497

Merged
merged 8 commits into from
Jul 16, 2024
15 changes: 14 additions & 1 deletion edb/testbase/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ def _iter_methods(bases, ns):
yield methname, meth

@classmethod
def wrap(mcls, meth):
def wrap(mcls, meth, is_repeat=False):
@functools.wraps(meth)
def wrapper(self, *args, __meth__=meth, **kwargs):
try_no = 1

if is_repeat and not getattr(self, 'TRANSACTION_ISOLATION', False):
raise unittest.SkipTest()

while True:
try:
# There might be unobvious serializability
Expand Down Expand Up @@ -216,6 +219,16 @@ def wrapper(self, *args, __meth__=meth, **kwargs):
def add_method(mcls, methname, ns, meth):
ns[methname] = mcls.wrap(meth)

# If EDGEDB_TEST_REPEATS is set, duplicate all the tests.
# This is valuable because it should exercise the function
# cache.
if (
os.environ.get('EDGEDB_TEST_REPEATS', None)
and methname.startswith('test_')
):
new = methname.replace('test_', 'test_zREPEAT_', 1)
ns[new] = mcls.wrap(meth, is_repeat=True)

def __new__(mcls, name, bases, ns):
for methname, meth in mcls._iter_methods(bases, ns.copy()):
if methname in ns:
Expand Down