Skip to content

Commit a130d69

Browse files
committed
Add regression test for methodcaller
1 parent 2b8ff15 commit a130d69

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import unittest
2+
from threading import Thread
3+
from test.support import threading_helper
4+
from operator import methodcaller
5+
6+
7+
class TestMethodcaller(unittest.TestCase):
8+
def test_methodcaller_threading(self):
9+
number_of_threads = 10
10+
size = 4_000
11+
12+
mc = methodcaller("append", 2)
13+
14+
def work(mc, l, ii):
15+
for _ in range(ii):
16+
mc(l)
17+
18+
worker_threads = []
19+
lists = []
20+
for ii in range(number_of_threads):
21+
l = []
22+
lists.append(l)
23+
worker_threads.append(Thread(target=work, args=[mc, l, size]))
24+
for t in worker_threads:
25+
t.start()
26+
for t in worker_threads:
27+
t.join()
28+
for l in lists:
29+
assert len(l) == size
30+
31+
32+
if __name__ == "__main__":
33+
unittest.main()

0 commit comments

Comments
 (0)