Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/net/ssh/multi/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def loop(wait=nil, &block)
# +false+ (the block returned +false+).
def process(wait=nil, &block)
realize_pending_connections!
wait = @connect_threads.any? ? 0 : wait
wait = @connect_threads.any? ? 0 : io_select_wait(wait)

return false unless preprocess(&block)

Expand All @@ -441,6 +441,15 @@ def process(wait=nil, &block)
end
end

def io_select_wait(wait)
[wait, keepalive_interval].compact.min
end

def keepalive_interval
servers = server_list.select { |s| s.options[:keepalive] }
servers.map { |s| s.options[:keepalive_interval] }.compact.min
end

# Runs the preprocess stage on all servers. Returns false if the block
# returns false, and true if there either is no block, or it returns true.
# This is called as part of the #process method.
Expand Down
21 changes: 21 additions & 0 deletions test/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,25 @@ def test_process_should_call_select_on_combined_readers_and_writers_from_all_ser
IO.expects(:select).with([:a, :b, :c], [:a, :c], nil, 5).returns([[:b, :c], [:a, :c]])
@session.process(5)
end

def test_process_should_pass_minimum_keepalive_interval_as_io_select_timeout
@session.use('h1', :keepalive => true)
@session.use('h2', :keepalive_interval => 1)
@session.use('h3', :keepalive => true, :keepalive_interval => 2)
@session.use('h4', :keepalive => true, :keepalive_interval => 3)
IO.expects(:select).with([], [], nil, 2)
@session.process
end

def test_process_should_pass_wait_as_io_select_timeout_if_provided_and_minimum
@session.use('h1', :keepalive => true, :keepalive_interval => 1)
IO.expects(:select).with([], [], nil, 1)
@session.process(2)
end

def test_process_should_pass_nil_as_io_select_timeout_by_default
@session.use('h1')
IO.expects(:select).with([], [], nil, nil)
@session.process
end
end