diff options
| author | Miklos Fazekas <mfazekas@szemafor.com> | 2017-01-18 21:17:08 +0100 |
|---|---|---|
| committer | Miklos Fazekas <mfazekas@szemafor.com> | 2017-01-19 16:53:34 +0100 |
| commit | dc0806dda3c4eb3a867940e2f5efd1448ae8e932 (patch) | |
| tree | 3f27796eb54d31e40c88d8330ea744b0ca9e7db8 /test/integration | |
| parent | 1d2e1755b7b348be3afa71ff411ca2fd9181667e (diff) | |
| download | net-ssh-dc0806dda3c4eb3a867940e2f5efd1448ae8e932.tar.gz | |
Shallow Errno::EPIPE as causes flaky tests
Diffstat (limited to 'test/integration')
| -rw-r--r-- | test/integration/test_forward.rb | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/test/integration/test_forward.rb b/test/integration/test_forward.rb index f98e5fd..47da7c9 100644 --- a/test/integration/test_forward.rb +++ b/test/integration/test_forward.rb @@ -21,7 +21,7 @@ require 'net/ssh/proxy/command' require 'timeout' require 'tempfile' -class TestForward < NetSSHTest +class ForwardTestBase < NetSSHTest include IntegrationTestHelpers def localhost @@ -65,7 +65,9 @@ class TestForward < NetSSHTest end return server end +end +class TestForward < ForwardTestBase def start_server_closing_soon(exceptions=nil) server = TCPServer.open(0) Thread.start do @@ -88,7 +90,6 @@ class TestForward < NetSSHTest def test_in_file_no_password setup_ssh_env do ret = Net::SSH.start(*ssh_start_params) do |ssh| - #ret = Net::SSH.start("localhost", "net_ssh_1", {keys: @key_id_rsa}) do |ssh| ssh.exec! 'echo "hello from:$USER"' end assert_equal "hello from:net_ssh_1\n", ret @@ -225,49 +226,6 @@ class TestForward < NetSSHTest end end - if defined?(UNIXServer) - def create_local_socket(&blk) - tempfile = Tempfile.new("net_ssh_forward_test") - path = tempfile.path - tempfile.delete - yield UNIXServer.open(path) - File.delete(path) - end - end - - if defined?(UNIXSocket) - def test_forward_local_unix_socket_to_remote_port - setup_ssh_env do - session = Net::SSH.start(*ssh_start_params) - server_exc = Queue.new - server = start_server_sending_lot_of_data(server_exc) - remote_port = server.addr[1] - client_data = nil - - create_local_socket do |local_socket| - session.forward.local(local_socket, localhost, remote_port) - client_done = Queue.new - - Thread.start do - begin - client = UNIXSocket.new(local_socket.path) - client_data = client.recv(1024) - client.close - sleep(0.2) - ensure - client_done << true - end - end - - session.loop(0.1) { client_done.empty? } - end - - assert_not_nil(client_data, "client should have received data") - assert(client_data.match(/item\d/), 'client should have received the string item') - end - end - end - def test_loop_should_not_abort_when_server_side_of_forward_is_closed setup_ssh_env do session = Net::SSH.start(*ssh_start_params) @@ -641,3 +599,49 @@ class TestForward < NetSSHTest end end end + +class TestForwardOnUnixSockets < ForwardTestBase + if defined?(UNIXServer) && defined?(UNIXSocket) + def create_local_socket(&blk) + tempfile = Tempfile.new("net_ssh_forward_test") + path = tempfile.path + tempfile.delete + yield UNIXServer.open(path) + File.delete(path) + end + + def test_forward_local_unix_socket_to_remote_port + setup_ssh_env do + session = Net::SSH.start(*ssh_start_params) + server_exc = Queue.new + server = start_server_sending_lot_of_data(server_exc) + remote_port = server.addr[1] + client_data = nil + + create_local_socket do |local_socket| + session.forward.local(local_socket, localhost, remote_port) + client_done = Queue.new + + Thread.start do + begin + client = UNIXSocket.new(local_socket.path) + client_data = client.recv(1024) + client.close + sleep(0.2) + ensure + client_done << true + end + end + + begin + session.loop(0.1) { client_done.empty? } + rescue Errno::EPIPE + end + end + + assert_not_nil(client_data, "client should have received data") + assert(client_data.match(/item\d/), 'client should have received the string item') + end + end + end +end |
