Add test to check when proxy times-out mid-write to upstream
I've add to add code to allow the environment to specify the upstream tiemout so we don't have to wait 30s for this test to happen.
This commit is contained in:
@@ -206,6 +206,56 @@ module ProxyTests
|
||||
end
|
||||
end
|
||||
|
||||
def test_write_request_retried_when_upstream_times_out_during_write_phase
|
||||
ENV['FLEXNBD_UPSTREAM_TIMEOUT'] = '4'
|
||||
maker = make_fake_server
|
||||
|
||||
with_ld_preload('setsockopt_logger') do
|
||||
with_proxied_client(4096) do |client|
|
||||
server, sc1 = maker.value
|
||||
|
||||
# Guess an approprate request size, based on the send buffer size.
|
||||
sz = sc1.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).int * 4
|
||||
data1 = (b * sz)
|
||||
|
||||
# Send the read request to the proxy
|
||||
client.write(0, data1)
|
||||
|
||||
# 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 data1.size, req1[:len]
|
||||
|
||||
# Need to sleep longer than the timeout set above
|
||||
sleep 5
|
||||
# Check the number of bytes that can be read from the socket without
|
||||
# blocking. If this equal to the size of the original request, then
|
||||
# the whole request has been buffered. If this is the case, then the
|
||||
# proxy will not time-out in the WRITE_UPSTREAM statem which is what
|
||||
# we're trying to test.
|
||||
assert sc1.nread < sz, 'Request from proxy completely buffered. Test is useless'
|
||||
|
||||
# Kill the server again, now we're sure the read request has been sent once
|
||||
sc1.close
|
||||
|
||||
# We expect the proxy to reconnect without our client doing anything.
|
||||
sc2 = server.accept
|
||||
sc2.write_hello
|
||||
|
||||
# And once reconnected, it should resend an identical request.
|
||||
req2 = sc2.read_request
|
||||
assert_equal req1, req2
|
||||
data2 = sc2.read_data(req2[:len])
|
||||
assert_equal data1, data2
|
||||
|
||||
sc2.close
|
||||
server.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_only_one_client_can_connect_to_proxy_at_a_time
|
||||
with_proxied_client do |_client|
|
||||
c2 = nil
|
||||
|
Reference in New Issue
Block a user