Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Reduce iteration count instead of skipping tests
  • Loading branch information
mpage committed Apr 11, 2024
commit 1ea81079e1159dce2e7c740a7e8f35cb3cee39aa
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