Skip to content

Commit

Permalink
Integrate the refleak run check into regrtest and test.support
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldoussoren committed Jan 14, 2024
1 parent 1fc2443 commit 8907efc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
8 changes: 7 additions & 1 deletion Lib/test/libregrtest/refleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from test import support
from test.support import os_helper
from test.support import refleak_helper

from .runtests import HuntRefleak
from .utils import clear_caches
Expand Down Expand Up @@ -96,7 +97,12 @@ def get_pooled_int(value):
support.gc_collect()

for i in rep_range:
results = test_func()
current = refleak_helper._hunting_for_refleaks
refleak_helper._hunting_for_refleaks = True
try:
results = test_func()
finally:
refleak_helper._hunting_for_refleaks = current

dash_R_cleanup(fs, ps, pic, zdc, abcs)
support.gc_collect()
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/support/refleak_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Utilities for changing test behaviour while hunting
for refleaks
"""

_hunting_for_refleaks = False
def hunting_for_refleaks():
return _hunting_for_refleaks
29 changes: 3 additions & 26 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from test.support import os_helper
from test.support import socket_helper
from test.support import threading_helper
from test.support import refleak_helper

import _thread as thread
import array
Expand Down Expand Up @@ -52,27 +53,6 @@
except ImportError:
_socket = None

_hunting_for_refleaks = None
def hunting_for_refleaks():
"""
Return true iff running tests while hunting for refleaks
"""
from test.libregrtest.runtests import RunTests
import gc

global _hunting_for_refleaks

if _hunting_for_refleaks is None:
for value in gc.get_objects():
if isinstance(value, RunTests):
_hunting_for_refleaks = (value.hunt_refleak is not None)
break
else:
_hunting_for_refleaks = False

return _hunting_for_refleaks


def skipForRefleakHuntinIf(condition, issueref):
if not condition:
def decorator(f):
Expand All @@ -83,15 +63,15 @@ def decorator(f):
def decorator(f):
@contextlib.wraps(f)
def wrapper(*args, **kwds):
if hunting_for_refleaks():
if refleak_helper.hunting_for_refleaks():
raise unittest.SkipTest(f"ignore while hunting for refleaks, see {issueref}")

return f(*args, **kwds)

def client_skip(f):
@contextlib.wraps(f)
def wrapper(*args, **kwds):
if hunting_for_refleaks():
if refleak_helper.hunting_for_refleaks():
return

return f(*args, **kwds)
Expand Down Expand Up @@ -3886,9 +3866,6 @@ def testCmsgTrunc0(self):

@testCmsgTrunc0.client_skip
def _testCmsgTrunc0(self):
if sys.platform == "darwin" and hunting_for_refleaks():
return

self.createAndSendFDs(1)

# Check that no ancillary data is returned for various non-zero
Expand Down

0 comments on commit 8907efc

Please sign in to comment.