Skip to content

Commit e64fe3c

Browse files
manually test for concurrent access
1 parent 8821d32 commit e64fe3c

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

unittests/test_itertools.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,29 @@ async def test_peer(peer_tee):
361361
assert results == items
362362

363363

364+
@pytest.mark.parametrize("concurrency", (1, 2, 4, 7))
364365
@sync
365-
async def test_tee_share() -> None:
366+
async def test_tee_share(concurrency: int) -> None:
366367
"""Test that related tees share their buffer and see all items"""
367368
items = [1, 2, 3, -5, 12, 78, -1, 111]
368369

370+
async def tee_test(tee_state: AsyncIterator[int]) -> None:
371+
"""Asynchronously check that `tee_state` includes all `items`"""
372+
for expected in items:
373+
assert expected == await a.anext(tee_state)
374+
await Switch(0, concurrency)
375+
376+
# create tees that are multiple times removed from an initial iterator
377+
item_iter = a.iter(items)
378+
for tee_peer in a.tee(item_iter, n=concurrency):
379+
await Schedule(tee_test(a.tee(tee_peer)[0]))
380+
381+
382+
@sync
383+
async def test_tee_share_deep() -> None:
384+
"""Test that related tees share their buffer and see all items no matter when spawned"""
385+
items = [1, 2, 3, -5, 12, 78, -1, 111]
386+
369387
async def tee_spawn_walker(
370388
tee_state: AsyncIterator[int], start_idx: int = 0
371389
) -> None:

0 commit comments

Comments
 (0)