Skip to content

Commit 8f0aeed

Browse files
committed
move test
1 parent 9a5991e commit 8f0aeed

2 files changed

Lines changed: 25 additions & 26 deletions

File tree

Lib/test/test_free_threading/test_list.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,31 @@ def reader_list(b, l):
149149
with threading_helper.start_threads(threads):
150150
pass
151151

152+
# gh-145036: race condition with list.__sizeof__()
153+
def test_list_sizeof_free_threaded_build(self):
154+
L = []
155+
156+
def test1():
157+
for _ in range(100):
158+
L.append(1)
159+
L.pop()
160+
161+
def test2():
162+
for _ in range(100):
163+
L.__sizeof__()
164+
165+
threads = []
166+
for _ in range(4):
167+
threads.append(Thread(target=test1))
168+
threads.append(Thread(target=test2))
169+
170+
for t in threads:
171+
t.start()
172+
for t in threads:
173+
t.join()
174+
175+
self.assertEqual(len(L), 0)
176+
152177

153178
if __name__ == "__main__":
154179
unittest.main()

Lib/test/test_list.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from test.support.import_helper import import_module
77
from test.support.script_helper import assert_python_failure, assert_python_ok
88
import pickle
9-
from threading import Thread
109
import unittest
1110

1211
class ListTest(list_tests.CommonTest):
@@ -382,30 +381,5 @@ def foo(x):
382381

383382
self.assertEqual(foo(list(range(10))), 45)
384383

385-
# gh-145036: race condition with list.__sizeof__()
386-
def test_list_sizeof_free_threaded_build(self):
387-
L = []
388-
389-
def test1():
390-
for _ in range(100):
391-
L.append(1)
392-
L.pop()
393-
394-
def test2():
395-
for _ in range(100):
396-
L.__sizeof__()
397-
398-
threads = []
399-
for _ in range(4):
400-
threads.append(Thread(target=test1))
401-
threads.append(Thread(target=test2))
402-
403-
for t in threads:
404-
t.start()
405-
for t in threads:
406-
t.join()
407-
408-
self.assertEqual(len(L), 0)
409-
410384
if __name__ == "__main__":
411385
unittest.main()

0 commit comments

Comments
 (0)