Check that TCP_NODELAY is set on upstream sockets on reconnection

Also rationalize the test to see if a function has been called.  Still
not great, but getting there :)
This commit is contained in:
Patrick J Cherry
2018-02-09 10:26:08 +00:00
parent c053a54faa
commit 8e67180999
5 changed files with 70 additions and 37 deletions

View File

@@ -39,4 +39,9 @@ module LdPreload
l.split(':').map { |i| i =~ /^\d+$/ ? i.to_i : i }
end
end
def assert_func_call(loglines, args, msg)
re = Regexp.new('^' + args.join(':'))
assert(loglines.any? { |l| l.match(re) }, msg)
end
end

View File

@@ -26,7 +26,7 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t
fn = getenv("OUTPUT_setsockopt_logger");
if ( fn != NULL && optval != NULL && optlen == 4) {
fd = fopen(fn,"a");
fprintf(fd,"setsockopt:%d:%d:%i:%d\n", level, optname, *(int *)optval, retval);
fprintf(fd,"setsockopt:%d:%d:%d:%i:%d\n", sockfd, level, optname, *(int *)optval, retval);
fclose(fd);
}

View File

@@ -147,6 +147,7 @@ module ProxyTests
def test_write_request_retried_when_upstream_dies_partway
maker = make_fake_server
with_ld_preload('setsockopt_logger') do
with_proxied_client(4096) do |client|
server, sc1 = maker.value
@@ -162,6 +163,10 @@ module ProxyTests
data1 = sc1.read_data(4096)
assert_equal((b * 4096), data1, 'Data not proxied successfully')
# Read the setsockopt logs, so we can check that TCP_NODELAY is re-set
# later
read_ld_preload_log('setsockopt_logger')
# Kill the server again, now we're sure the read request has been sent once
sc1.close
@@ -186,6 +191,14 @@ module ProxyTests
sc2.close
server.close
# Check TCP_NODELAY was set on the upstream socket
log = read_ld_preload_log('setsockopt_logger')
assert_func_call(log,
['setsockopt', 3,
Socket::SOL_TCP, Socket::TCP_NODELAY, 1, 0],
'TCP_NODELAY not set on upstream fd 3')
end
end
end

View File

@@ -1,8 +1,11 @@
require 'test/unit'
require 'environment'
require 'ld_preload'
require 'proxy_tests'
class TestProxyMode < Test::Unit::TestCase
include LdPreload
include ProxyTests
def setup

View File

@@ -188,11 +188,23 @@ class TestServeMode < Test::Unit::TestCase
def test_server_sets_tcpkeepalive
with_ld_preload('setsockopt_logger') do
connect_to_server(&:close)
op = parse_ld_preload_logs('setsockopt_logger')
assert(op.any? { |e| e == ['setsockopt', Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1, 0] }, 'TCP Keepalive not successfully set')
assert(op.any? { |e| e == ['setsockopt', Socket::SOL_TCP, Socket::TCP_KEEPIDLE, 30, 0] }, 'TCP Keepalive idle timeout not set to 30s')
assert(op.any? { |e| e == ['setsockopt', Socket::SOL_TCP, Socket::TCP_KEEPINTVL, 10, 0] }, 'TCP keepalive retry time not set to 10s')
assert(op.any? { |e| e == ['setsockopt', Socket::SOL_TCP, Socket::TCP_KEEPCNT, 3, 0] }, 'TCP keepalive count not set to 3')
op = read_ld_preload_log('setsockopt_logger')
assert_func_call(op,
['setsockopt', '\d+',
Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1, 0],
'TCP Keepalive not successfully set')
assert_func_call(op,
['setsockopt', '\d+',
Socket::SOL_TCP, Socket::TCP_KEEPIDLE, 30, 0],
'TCP Keepalive idle timeout not set to 30s')
assert_func_call(op,
['setsockopt', '\d+',
Socket::SOL_TCP, Socket::TCP_KEEPINTVL, 10, 0],
'TCP keepalive retry time not set to 10s')
assert_func_call(op,
['setsockopt', '\d+',
Socket::SOL_TCP, Socket::TCP_KEEPCNT, 3, 0],
'TCP keepalive count not set to 3')
end
end
end