diff options
author | elijah <elijah@riseup.net> | 2016-08-29 16:35:14 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-09-01 10:13:31 -0700 |
commit | 07c0e60e6bdc5b8bfe1f42f76dae9f0a79e7abb0 (patch) | |
tree | 9f79f8fbb207896dcfe38f24831d9b2b857199a4 /tests/helpers/network_helper.rb | |
parent | d5bac5850e4a895da5f9cfacb641fab15de1cf7b (diff) |
moved infrastructure tests run by `leap run` to tests/server-tests
Diffstat (limited to 'tests/helpers/network_helper.rb')
-rw-r--r-- | tests/helpers/network_helper.rb | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/tests/helpers/network_helper.rb b/tests/helpers/network_helper.rb deleted file mode 100644 index 713d57aa..00000000 --- a/tests/helpers/network_helper.rb +++ /dev/null @@ -1,79 +0,0 @@ -class LeapTest - - # - # tcp connection helper with timeout - # - def try_tcp_connect(host, port, timeout = 5) - addr = Socket.getaddrinfo(host, nil) - sockaddr = Socket.pack_sockaddr_in(port, addr[0][3]) - - Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0).tap do |socket| - socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) - begin - socket.connect_nonblock(sockaddr) - rescue IO::WaitReadable - if IO.select([socket], nil, nil, timeout) == nil - raise "Connection timeout" - else - socket.connect_nonblock(sockaddr) - end - rescue IO::WaitWritable - if IO.select(nil, [socket], nil, timeout) == nil - raise "Connection timeout" - else - socket.connect_nonblock(sockaddr) - end - end - return socket - end - end - - def try_tcp_write(socket, timeout = 5) - begin - socket.write_nonblock("\0") - rescue IO::WaitReadable - if IO.select([socket], nil, nil, timeout) == nil - raise "Write timeout" - else - retry - end - rescue IO::WaitWritable - if IO.select(nil, [socket], nil, timeout) == nil - raise "Write timeout" - else - retry - end - end - end - - def try_tcp_read(socket, timeout = 5) - begin - socket.read_nonblock(1) - rescue IO::WaitReadable - if IO.select([socket], nil, nil, timeout) == nil - raise "Read timeout" - else - retry - end - rescue IO::WaitWritable - if IO.select(nil, [socket], nil, timeout) == nil - raise "Read timeout" - else - retry - end - end - end - - def assert_tcp_socket(host, port, msg=nil) - begin - socket = try_tcp_connect(host, port, 1) - #try_tcp_write(socket,1) - #try_tcp_read(socket,1) - rescue StandardError => exc - fail ["Failed to open socket #{host}:#{port}", exc, msg].compact.join("\n") - ensure - socket.close if socket - end - end - -end
\ No newline at end of file |