def test_slow_receiving_client(self):
"""
This test checks that the NGAS server doesn't hang forever on a slow
client, since it would block the server for ever
"""
timeout = 3
amount_of_data = 10*1024*1024 # 10 MBs
spaces = " " * amount_of_data
self.prepExtSrv(cfgProps=[["NgamsCfg.Server[1].TimeOut",str(timeout)]])
client = sendPclCmd()
status = client.archive_data(spaces, 'some-file.data', 'application/octet-stream')
self.assertEquals(NGAMS_SUCCESS, status.getStatus())
# Normal retrieval works fine
self.assertEquals(NGAMS_SUCCESS, client.retrieve(fileId='some-file.data').getStatus())
os.unlink('some-file.data')
# Now retrieve the data, but sloooooooooooowly and check that the server
# times out and closes the connection, which in turn makes our receiving
# end finish earlier than expected. This is detected on the client side
# because we receive less data than we ask for).
#
# We have to make sure that the receiving buffer is tiny so the server
# really can't write any more data into the socket. In the same spirit
# we specify a very small send buffer for the server. We don't need to
# specify a timeout because the recv will return immediately if the
# server has closed the connection.
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 256)
s.connect(('localhost', 8888))
s.send('GET /RETRIEVE?file_id=some-file.data&send_buffer=1024 HTTP/1.0\r\n')
s.send('\r\n')
time.sleep(timeout + 2) # More than enough to provoke a server timeout
data = s.recv(amount_of_data, socket.MSG_WAITALL)
self.assertLess(len(data), amount_of_data, "Should have read less data")
self.assertEquals('', s.recv(amount_of_data - len(data)))
s.close()
评论列表
文章目录