diff options
author | Norihito Yoshioka <nori.yoshioka@gmail.com> | 2013-08-18 22:25:26 +0900 |
---|---|---|
committer | Norihito Yoshioka <nori.yoshioka@gmail.com> | 2013-08-18 22:25:26 +0900 |
commit | be70cb70b1af8f2aed4748220ed7e0967278470a (patch) | |
tree | d6904c24954a585ff2ba75798a4ada71702c6bd6 /test | |
parent | 8bdef39d5b572b7a630ed007b8d6fe0da946a395 (diff) | |
download | net-ssh-be70cb70b1af8f2aed4748220ed7e0967278470a.tar.gz |
implement a experimental keepalive feature
Diffstat (limited to 'test')
-rw-r--r-- | test/connection/test_session.rb | 38 | ||||
-rw-r--r-- | test/start/test_options.rb | 29 |
2 files changed, 67 insertions, 0 deletions
diff --git a/test/connection/test_session.rb b/test/connection/test_session.rb index 24ac4a4..8af6cd3 100644 --- a/test/connection/test_session.rb +++ b/test/connection/test_session.rb @@ -363,6 +363,44 @@ module Connection session.process end + def test_process_should_call_enqueue_message_if_io_select_timed_out + timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT + options = { :keepalive => true } + expected_packet = P(:byte, Net::SSH::Packet::IGNORE, :string, "keepalive") + IO.stubs(:select).with([socket],[],nil,timeout).returns(nil) + transport.expects(:enqueue_message).with{ |msg| msg.content == expected_packet.content } + session(options).process + end + + def test_process_should_not_call_enqueue_message_unless_io_select_timed_out + timeout = Net::SSH::Connection::Session::DEFAULT_IO_SELECT_TIMEOUT + options = { :keepalive => true } + IO.stubs(:select).with([socket],[],nil,timeout).returns([[],[],[]]) + transport.expects(:enqueue_message).never + session(options).process + end + + def test_process_should_not_call_enqueue_message_unless_keepalive_interval_not_go_on + timeout = 10 + options = { :keepalive => true, :keepalive_interval => timeout } + Time.stubs(:now).returns(Time.at(0), Time.at(9), Time.at(timeout)) + IO.stubs(:select).with([socket],[],nil,timeout).returns(nil) + transport.expects(:enqueue_message).times(2) + 3.times { session(options).process } + end + + def test_process_should_call_io_select_with_nil_as_last_arg_if_keepalive_disabled + IO.expects(:select).with([socket],[],nil,nil).returns([[],[],[]]) + session.process + end + + def test_process_should_call_io_select_with_interval_as_last_arg_if_keepalive_interval_passed + timeout = 10 + options = { :keepalive => true, :keepalive_interval => timeout } + IO.expects(:select).with([socket],[],nil,timeout).returns([[],[],[]]) + session(options).process + end + def test_loop_should_call_process_until_process_returns_false IO.stubs(:select).with([socket],[],nil,nil).returns([[],[],[]]) session.expects(:process).with(nil).times(4).returns(true,true,true,false).yields diff --git a/test/start/test_options.rb b/test/start/test_options.rb new file mode 100644 index 0000000..0d38f6a --- /dev/null +++ b/test/start/test_options.rb @@ -0,0 +1,29 @@ +require 'common' +require 'net/ssh' + +module NetSSH + class TestStartOptions < Test::Unit::TestCase + def setup + authentication_session = mock('authentication_session') + authentication_session.stubs(:authenticate).returns(true) + Net::SSH::Authentication::Session.stubs(:new).returns(authentication_session) + Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session')) + Net::SSH::Connection::Session.stubs(:new).returns(mock('connection_session')) + end + + def test_start_should_accept_keepalive_option + assert_nothing_raised do + options = { :keepalive => true } + Net::SSH.start('localhost', 'testuser', options) + end + end + + def test_start_should_accept_keepalive_interval_option + assert_nothing_raised do + options = { :keepalive_interval => 10 } + Net::SSH.start('localhost', 'testuser', options) + end + end + end +end + |