Skip to content

Commit bb6ef55

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

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/test_stream.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import logging
44
import math
55
from operator import itemgetter
6+
import queue
67
import random
8+
import threading
79
import time
810
import timeit
911
import traceback
10-
from types import FrameType, TracebackType
12+
from types import FrameType
1113
import unittest
1214
from collections import Counter
1315
from typing import (
@@ -18,6 +20,7 @@
1820
Iterable,
1921
Iterator,
2022
List,
23+
Optional,
2124
Set,
2225
Tuple,
2326
Type,
@@ -1846,3 +1849,20 @@ def test_ref_cycles(self) -> None:
18461849
],
18471850
msg=f"the exception's traceback should not contain an exception that captures itself in its own traceback",
18481851
)
1852+
1853+
def test_on_queue_in_thread(self) -> None:
1854+
zeros: List[str] = []
1855+
src: "queue.Queue[Optional[str]]" = queue.Queue()
1856+
thread = threading.Thread(
1857+
target=Stream(iter(src.get, None)).foreach(zeros.append)
1858+
)
1859+
thread.start()
1860+
src.put("foo")
1861+
src.put("bar")
1862+
src.put(None)
1863+
thread.join()
1864+
self.assertListEqual(
1865+
zeros,
1866+
["foo", "bar"],
1867+
msg="stream must work on Queue",
1868+
)

0 commit comments

Comments
 (0)