Files
impala/shell/ext-py/thrift-0.16.0/test/test_socket.py
Joe McDonnell a9cfc7b33f IMPALA-11624: Bump Impyla dependency to 0.18.0
IMPALA_THRIFT_PY_VERSION is also bumped to 0.16.0p3.
As 0.16.0p3 Thrift does not contain Python related
patches and Impyla 0.18.0 depends on Thrift 0.16.0,
now we are consistently using Thrift 0.16.0 in all
Python code. This also bumps the Thrift in the
shell's ext-py directory to 0.16.0 (based on the
Thrift 0.16.0 pypi tarball with the egg directory
removed).

Testing:
 - Ran a GVO job

Change-Id: I7265558b0e07959c606cba73cd251c3edfcb3ed5
Reviewed-on: http://gerrit.cloudera.org:8080/18456
Reviewed-by: Michael Smith <michael.smith@cloudera.com>
Reviewed-by: Wenzhe Zhou <wzhou@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
2023-02-27 20:39:26 +00:00

58 lines
1.8 KiB
Python

import errno
import unittest
from test_sslsocket import ServerAcceptor
import _import_local_thrift # noqa
from thrift.transport.TSocket import TServerSocket
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TTransportException
class TSocketTest(unittest.TestCase):
def test_isOpen_checks_for_readability(self):
# https://docs.python.org/3/library/socket.html#notes-on-socket-timeouts
# https://docs.python.org/3/library/socket.html#socket.socket.settimeout
timeouts = [
None, # blocking mode
0, # non-blocking mode
1.0, # timeout mode
]
for timeout in timeouts:
acc = ServerAcceptor(TServerSocket(port=0))
acc.start()
sock = TSocket(host="localhost", port=acc.port)
sock.open()
sock.setTimeout(timeout)
# the socket shows as open immediately after connecting
self.assertTrue(sock.isOpen())
# and remains open during usage
sock.write(b"hello")
self.assertTrue(sock.isOpen())
while True:
try:
sock.read(5)
except TTransportException as exc:
if exc.inner.errno == errno.EAGAIN:
# try again when we're in non-blocking mode
continue
raise
break
self.assertTrue(sock.isOpen())
# once the server side closes, it no longer shows open
acc.client.close() # this also blocks until the other thread is done
acc.close()
self.assertFalse(sock.isOpen())
sock.close()
if __name__ == "__main__":
unittest.main()