Skip to content

Commit 50e2fa7

Browse files
committed
test_stream: add test_on_queue_in_thread
1 parent 0cae4e6 commit 50e2fa7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/test_stream.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import asyncio
2+
from contextlib import suppress
23
import datetime
34
import logging
45
import math
56
from operator import itemgetter
7+
import queue
68
import random
9+
import threading
710
import time
811
import timeit
912
import traceback
10-
from types import FrameType, TracebackType
13+
from types import FrameType
1114
import unittest
1215
from collections import Counter
1316
from typing import (
@@ -18,6 +21,7 @@
1821
Iterable,
1922
Iterator,
2023
List,
24+
Optional,
2125
Set,
2226
Tuple,
2327
Type,
@@ -1846,3 +1850,20 @@ def test_ref_cycles(self) -> None:
18461850
],
18471851
msg=f"the exception's traceback should not contain an exception that captures itself in its own traceback",
18481852
)
1853+
1854+
def test_on_queue_in_thread(self) -> None:
1855+
zeros: List[str] = []
1856+
src: "queue.Queue[Optional[str]]" = queue.Queue()
1857+
thread = threading.Thread(
1858+
target=Stream(iter(src.get, None)).foreach(zeros.append)
1859+
)
1860+
thread.start()
1861+
src.put("foo")
1862+
src.put("bar")
1863+
src.put(None)
1864+
thread.join()
1865+
self.assertListEqual(
1866+
zeros,
1867+
["foo", "bar"],
1868+
msg="stream must work on Queue",
1869+
)

0 commit comments

Comments
 (0)