Skip to content

Commit 66f0e6c

Browse files
committed
Per review, refactor extend test to extend multiple times, and reduce total time to run tests (both tests combine to less than 200 ms in debug build on my laptop)
1 parent 707852d commit 66f0e6c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Lib/test/test_free_threading/test_str.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import unittest
33

44
from itertools import cycle
5-
from threading import Thread
5+
from threading import Event, Thread
66
from unittest import TestCase
77

88
from test.support import threading_helper
@@ -12,21 +12,20 @@ class TestStr(TestCase):
1212
def test_racing_join_extend(self):
1313
'''Test joining a string being extended by another thread'''
1414
l = []
15-
OBJECT_COUNT = 100_000
16-
15+
ITERS = 100
16+
READERS = 10
17+
done_event = Event()
1718
def writer_func():
18-
l.extend(map(str, range(OBJECT_COUNT, OBJECT_COUNT*2)))
19-
19+
for i in range(ITERS):
20+
l.extend(map(str, range(i)))
21+
l.clear()
22+
done_event.set()
2023
def reader_func():
21-
while True:
22-
count = len(l)
24+
while not done_event.is_set():
2325
''.join(l)
24-
if count == OBJECT_COUNT:
25-
break
26-
2726
writer = Thread(target=writer_func)
2827
readers = []
29-
for x in range(30):
28+
for x in range(READERS):
3029
reader = Thread(target=reader_func)
3130
readers.append(reader)
3231
reader.start()
@@ -42,7 +41,8 @@ def test_racing_join_replace(self):
4241
strings by another thread.
4342
'''
4443
l = [*'abcdefg']
45-
MAX_ORDINAL = 10_000
44+
MAX_ORDINAL = 1_000
45+
READERS = 20
4646

4747
def writer_func():
4848
for i, c in zip(cycle(range(len(l))),
@@ -59,7 +59,7 @@ def reader_func():
5959

6060
writer = Thread(target=writer_func)
6161
readers = []
62-
for x in range(30):
62+
for x in range(READERS):
6363
reader = Thread(target=reader_func)
6464
readers.append(reader)
6565
reader.start()

0 commit comments

Comments
 (0)