Skip to content

Commit

Permalink
Reduce iteration count instead of skipping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Apr 11, 2024
1 parent 8f18671 commit 1ea8107
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Lib/test/test_weakref.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ def collect():
t.join()


skip_if_tsan_and_gil_disabled = unittest.skipIf(
support.check_sanitizer(thread=True) and support.Py_GIL_DISABLED,
"Test is prohibitively slow with TSAN enabled and the GIL disabled")


class ReferencesTestCase(TestBase):

def test_basic_ref(self):
Expand Down Expand Up @@ -1260,6 +1255,12 @@ class MappingTestCase(TestBase):

COUNT = 10

if support.check_sanitizer(thread=True) and support.Py_GIL_DISABLED:
# Reduce iteration count to get acceptable latency
NUM_THREADED_ITERATIONS = 1000
else:
NUM_THREADED_ITERATIONS = 100000

def check_len_cycles(self, dict_type, cons):
N = 20
items = [RefCycle() for i in range(N)]
Expand Down Expand Up @@ -1882,33 +1883,30 @@ def test_make_weak_keyed_dict_repr(self):
self.assertRegex(repr(dict), '<WeakKeyDictionary at 0x.*>')

@threading_helper.requires_working_threading()
@skip_if_tsan_and_gil_disabled
def test_threaded_weak_valued_setdefault(self):
d = weakref.WeakValueDictionary()
with collect_in_thread():
for i in range(100000):
for i in range(self.NUM_THREADED_ITERATIONS):
x = d.setdefault(10, RefCycle())
self.assertIsNot(x, None) # we never put None in there!
del x

@threading_helper.requires_working_threading()
@skip_if_tsan_and_gil_disabled
def test_threaded_weak_valued_pop(self):
d = weakref.WeakValueDictionary()
with collect_in_thread():
for i in range(100000):
for i in range(self.NUM_THREADED_ITERATIONS):
d[10] = RefCycle()
x = d.pop(10, 10)
self.assertIsNot(x, None) # we never put None in there!

@threading_helper.requires_working_threading()
@skip_if_tsan_and_gil_disabled
def test_threaded_weak_valued_consistency(self):
# Issue #28427: old keys should not remove new values from
# WeakValueDictionary when collecting from another thread.
d = weakref.WeakValueDictionary()
with collect_in_thread():
for i in range(200000):
for i in range(2 * self.NUM_THREADED_ITERATIONS):
o = RefCycle()
d[10] = o
# o is still alive, so the dict can't be empty
Expand Down

0 comments on commit 1ea8107

Please sign in to comment.