File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,9 +39,28 @@ def __init__(self):
3939 def start (self ):
4040 self .start_calls += 1
4141
42- def join (self ):
42+ def join (self , timeout = None ):
4343 self .join_calls += 1
4444
45+ def is_alive (self ):
46+ return False
47+
48+
49+ class HangingProcess (FakeProcess ):
50+ def __init__ (self ):
51+ super ().__init__ ()
52+ self .join_timeouts = []
53+ self .terminate_calls = 0
54+
55+ def join (self , timeout = None ):
56+ self .join_timeouts .append (timeout )
57+
58+ def is_alive (self ):
59+ return True
60+
61+ def terminate (self ):
62+ self .terminate_calls += 1
63+
4564
4665class FakeQueue :
4766 def __init__ (self ):
@@ -108,6 +127,17 @@ def test_close_is_idempotent_and_sends_one_poison_pill():
108127 assert len (writer .queue_ .items ) == 1
109128
110129
130+ def test_close_terminates_worker_after_join_timeout ():
131+ writer = make_writer (close_timeout = 0.01 )
132+ writer .process = HangingProcess ()
133+ writer .queue_ = FakeQueue ()
134+ writer .start ()
135+ writer .close ()
136+
137+ assert writer .process .join_timeouts == [0.01 , 0.01 ]
138+ assert writer .process .terminate_calls == 1
139+
140+
111141def test_context_manager_uses_close ():
112142 writer = make_writer ()
113143 writer .start = Mock ()
You can’t perform that action at this time.
0 commit comments