Skip to content

Commit 1ac4fd9

Browse files
test: add a regression test for bytearray.resize thread safety
1 parent 2511674 commit 1ac4fd9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/test/test_bytes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,19 @@ def check(funcs, it):
29082908
check([iter_next] + [iter_reduce] * 10, iter(ba)) # for tsan
29092909
check([iter_next] + [iter_setstate] * 10, iter(ba)) # for tsan
29102910

2911+
def test_free_threading_bytearray_resize(self):
2912+
def resize_stress(ba):
2913+
for _ in range(100_000):
2914+
try:
2915+
ba.resize(10_000)
2916+
ba.resize(1)
2917+
except (BufferError, ValueError):
2918+
pass
2919+
2920+
ba = bytearray(100)
2921+
threads = [threading.Thread(target=resize_stress, args=(ba,)) for _ in range(4)]
2922+
for t in threads: t.start()
2923+
for t in threads: t.join()
29112924

29122925
if __name__ == "__main__":
29132926
unittest.main()

0 commit comments

Comments
 (0)