File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ def try_create options = {} # :nodoc:
63
63
if @created >= @max && @enqueued >= 1
64
64
oldest , = @lru . first
65
65
@lru . delete oldest
66
- @ques [ oldest ] . pop
66
+ connection = @ques [ oldest ] . pop
67
+ connection . close if connection . respond_to? ( :close )
67
68
68
69
@created -= 1
69
70
end
Original file line number Diff line number Diff line change 4
4
class TestNetHttpPersistentTimedStackMulti < Minitest ::Test
5
5
6
6
class Connection
7
- attr_reader :host
7
+ attr_reader :host , :closed
8
8
9
9
def initialize ( host )
10
10
@host = host
11
+ @closed = false
12
+ end
13
+
14
+ def close
15
+ @closed = true
11
16
end
12
17
end
13
18
@@ -69,6 +74,18 @@ def test_pop_full
69
74
assert_empty stack
70
75
end
71
76
77
+ def test_pop_closes_extra_connections
78
+ stack = Net ::HTTP ::Persistent ::TimedStackMulti . new ( 1 ) { |host | Connection . new ( host ) }
79
+
80
+ a_conn = stack . pop connection_args : 'a.example'
81
+ stack . push a_conn , connection_args : 'a.example'
82
+
83
+ b_conn = stack . pop connection_args : 'b.example'
84
+
85
+ assert a_conn . closed
86
+ refute b_conn . closed
87
+ end
88
+
72
89
def test_pop_wait
73
90
thread = Thread . start do
74
91
@stack . pop
You can’t perform that action at this time.
0 commit comments