Merge branch 'rationalise-ld-preload-tests' into develop

This commit is contained in:
James F. Carter
2018-02-14 16:48:57 +00:00
6 changed files with 201 additions and 91 deletions

View File

@@ -1,8 +1,12 @@
require 'flexnbd/fake_source'
require 'flexnbd/fake_dest'
require 'ld_preload'
module ProxyTests
include LdPreload
def b
"\xFF".b
end
@@ -147,45 +151,58 @@ module ProxyTests
def test_write_request_retried_when_upstream_dies_partway
maker = make_fake_server
with_proxied_client(4096) do |client|
server, sc1 = maker.value
with_ld_preload('setsockopt_logger') do
with_proxied_client(4096) do |client|
server, sc1 = maker.value
# Send the read request to the proxy
client.write(0, (b * 4096))
# Send the read request to the proxy
client.write(0, (b * 4096))
# ensure we're given the read request
req1 = sc1.read_request
assert_equal ::FlexNBD::REQUEST_MAGIC, req1[:magic]
assert_equal ::FlexNBD::REQUEST_WRITE, req1[:type]
assert_equal 0, req1[:from]
assert_equal 4096, req1[:len]
data1 = sc1.read_data(4096)
assert_equal((b * 4096), data1, 'Data not proxied successfully')
# ensure we're given the read request
req1 = sc1.read_request
assert_equal ::FlexNBD::REQUEST_MAGIC, req1[:magic]
assert_equal ::FlexNBD::REQUEST_WRITE, req1[:type]
assert_equal 0, req1[:from]
assert_equal 4096, req1[:len]
data1 = sc1.read_data(4096)
assert_equal((b * 4096), data1, 'Data not proxied successfully')
# Kill the server again, now we're sure the read request has been sent once
sc1.close
# Read the setsockopt logs, so we can check that TCP_NODELAY is re-set
# later
read_ld_preload_log('setsockopt_logger')
# We expect the proxy to reconnect without our client doing anything.
sc2 = server.accept
sc2.write_hello
# Kill the server again, now we're sure the read request has been sent once
sc1.close
# And once reconnected, it should resend an identical request.
req2 = sc2.read_request
assert_equal req1, req2
data2 = sc2.read_data(4096)
assert_equal data1, data2
# We expect the proxy to reconnect without our client doing anything.
sc2 = server.accept
sc2.write_hello
# The reply should be proxied back to the client.
sc2.write_reply(req2[:handle])
# And once reconnected, it should resend an identical request.
req2 = sc2.read_request
assert_equal req1, req2
data2 = sc2.read_data(4096)
assert_equal data1, data2
# Check it to make sure it's correct
rsp = Timeout.timeout(15) { client.read_response }
assert_equal ::FlexNBD::REPLY_MAGIC, rsp[:magic]
assert_equal 0, rsp[:error]
assert_equal req1[:handle], rsp[:handle]
# The reply should be proxied back to the client.
sc2.write_reply(req2[:handle])
sc2.close
server.close
# Check it to make sure it's correct
rsp = Timeout.timeout(15) { client.read_response }
assert_equal ::FlexNBD::REPLY_MAGIC, rsp[:magic]
assert_equal 0, rsp[:error]
assert_equal req1[:handle], rsp[:handle]
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