Skip to content

Commit 095e20e

Browse files
committed
test iter_reduce and iter_setstate
1 parent b41ca85 commit 095e20e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Lib/test/test_bytes.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,12 +2521,20 @@ def check(funcs, a=None, *args):
25212521
@threading_helper.requires_working_threading()
25222522
def test_free_threading_bytearrayiter(self):
25232523
# Non-deterministic but good chance to fail if bytearrayiter is not free-threading safe.
2524-
# We are fishing for a "Assertion failed: object has negative ref count".
2524+
# We are fishing for a "Assertion failed: object has negative ref count" and tsan races.
25252525

25262526
def iter_next(b, it):
25272527
b.wait()
25282528
list(it)
25292529

2530+
def iter_reduce(b, it):
2531+
b.wait()
2532+
it.__reduce__()
2533+
2534+
def iter_setstate(b, it):
2535+
b.wait()
2536+
it.__setstate__(0)
2537+
25302538
def check(funcs, it):
25312539
barrier = threading.Barrier(len(funcs))
25322540
threads = []
@@ -2543,6 +2551,8 @@ def check(funcs, it):
25432551
ba = bytearray(b'0' * 0x4000) # this is a load-bearing variable, do not remove
25442552

25452553
check([iter_next] * 10, iter(ba))
2554+
check([iter_next] + [iter_reduce] * 10, iter(ba)) # for tsan
2555+
check([iter_next] + [iter_setstate] * 10, iter(ba)) # for tsan
25462556

25472557

25482558
if __name__ == "__main__":

0 commit comments

Comments
 (0)