THRIFT-847 Test Framework harmonization across all languages
Added 'ssl' tests for python tests.
Added '-transport arg (=buffered) transport: buffered, framed, http' to test/py/TestServer.py and test/py/TestClient.py and removed '-framed' arguement.
Changed test/py/RunClientServer.py to match above changes.
Added tests to compact protocol in python cases.
Added tests to test BinaryAccelarated protocol with Binary Protocol.
Changed py/TestClient.py and py/TestServer.py from --proto to --protocol parameter
Patch: Chamila Dilshan Wijayarathna & Roger Meier
diff --git a/test/py/RunClientServer.py b/test/py/RunClientServer.py
index 782bd83..46c9f8a 100755
--- a/test/py/RunClientServer.py
+++ b/test/py/RunClientServer.py
@@ -34,10 +34,10 @@
help='directory extensions for generated code, used as suffixes for \"gen-py-*\" added sys.path for individual tests')
parser.add_option("--port", type="int", dest="port", default=9090,
help="port number for server to listen on")
-parser.add_option('-v', '--verbose', action="store_const",
+parser.add_option('-v', '--verbose', action="store_const",
dest="verbose", const=2,
help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
+parser.add_option('-q', '--quiet', action="store_const",
dest="verbose", const=0,
help="minimal output")
parser.set_defaults(verbose=1)
@@ -107,14 +107,14 @@
ret = subprocess.call(script_args)
if ret != 0:
raise Exception("Script subprocess failed, retcode=%d, args: %s" % (ret, ' '.join(script_args)))
-
+
def runServiceTest(genpydir, server_class, proto, port, use_zlib, use_ssl):
# Build command line arguments
server_args = [sys.executable, relfile('TestServer.py') ]
cli_args = [sys.executable, relfile('TestClient.py') ]
for which in (server_args, cli_args):
which.append('--genpydir=%s' % genpydir)
- which.append('--proto=%s' % proto) # accel, binary or compact
+ which.append('--protocol=%s' % proto) # accel, binary or compact
which.append('--port=%d' % port) # default to 9090
if use_zlib:
which.append('--zlib')
@@ -128,7 +128,9 @@
server_args.append(server_class)
# client-specific cmdline options
if server_class in FRAMED:
- cli_args.append('--framed')
+ cli_args.append('--transport=framed')
+ else:
+ cli_args.append('--transport=buffered')
if server_class == 'THttpServer':
cli_args.append('--http=/')
if options.verbose > 0:
@@ -186,7 +188,7 @@
for genpydir in generated_dirs:
for script in SCRIPTS:
runScriptTest(genpydir, script)
-
+
print '----------------'
print ' Executing Client/Server tests with various generated code directories'
print ' Servers to be tested: ' + ', '.join(SERVERS)
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 18aea86..fd6b8e9 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -40,18 +40,18 @@
help="use SSL for encrypted transport")
parser.add_option("--multiple", action="store_true", dest="multiple",
help="use Multiple service")
-parser.add_option("--framed", action="store_true", dest="framed",
- help="use framed transport")
parser.add_option("--http", dest="http_path",
help="Use the HTTP transport with the specified path")
-parser.add_option('-v', '--verbose', action="store_const",
+parser.add_option('-v', '--verbose', action="store_const",
dest="verbose", const=2,
help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
+parser.add_option('-q', '--quiet', action="store_const",
dest="verbose", const=0,
help="minimal output")
-parser.add_option('--proto', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact")
+parser.add_option('--protocol', dest="proto", type="string",
+ help="protocol to use, one of: accel, binary, compact, json")
+parser.add_option('--transport', dest="trans", type="string",
+ help="transport to use, one of: buffered, framed")
parser.set_defaults(framed=False, http_path=None, verbose=1, host='localhost', port=9090, proto='binary')
options, args = parser.parse_args()
@@ -79,10 +79,13 @@
else:
socket = TSocket.TSocket(options.host, options.port)
# frame or buffer depending upon args
- if options.framed:
+ self.transport = TTransport.TBufferedTransport(socket)
+ if options.trans == 'framed':
self.transport = TTransport.TFramedTransport(socket)
- else:
+ elif options.trans == 'buffered':
self.transport = TTransport.TBufferedTransport(socket)
+ elif options.trans == '':
+ raise AssertionError('Unknown --transport option: %s' % options.trans)
if options.zlib:
self.transport = TZlibTransport.TZlibTransport(self.transport, 9)
self.transport.open()
@@ -180,7 +183,7 @@
xpected.i64_thing,
{ 0:'abc' },
Numberz.FIVE,
- 0xf0f0f0)
+ 0xf0f0f0)
self.assertEqual(y, xpected)
def testException(self):
@@ -208,7 +211,7 @@
end = time.time()
self.assertTrue(end - start < 3,
"oneway sleep took %f sec" % (end - start))
-
+
def testOnewayThenNormal(self):
self.client.testOneway(1) # type is int, not float
self.assertEqual(self.client.testString('Python'), 'Python')
@@ -241,7 +244,7 @@
elif options.proto == 'json':
suite.addTest(loader.loadTestsFromTestCase(JSONTest))
else:
- raise AssertionError('Unknown protocol given with --proto: %s' % options.proto)
+ raise AssertionError('Unknown protocol given with --protocol: %s' % options.proto)
return suite
class OwnArgsTestProgram(unittest.TestProgram):
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 8022341..6ee0399 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -35,14 +35,16 @@
help="use SSL for encrypted transport")
parser.add_option("--multiple", action="store_true", dest="multiple",
help="use multiple service")
-parser.add_option('-v', '--verbose', action="store_const",
+parser.add_option('-v', '--verbose', action="store_const",
dest="verbose", const=2,
help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
+parser.add_option('-q', '--quiet', action="store_const",
dest="verbose", const=0,
help="minimal output")
-parser.add_option('--proto', dest="proto", type="string",
+parser.add_option('--protocol', dest="proto", type="string",
help="protocol to use, one of: accel, binary, compact, json")
+parser.add_option('--transport', dest="trans", type="string",
+ help="transport to use, one of: buffered, framed")
parser.set_defaults(port=9090, verbose=1, proto='binary')
options, args = parser.parse_args()
@@ -185,10 +187,10 @@
byte_thing=arg0, i32_thing=arg1, i64_thing=arg2)
-# set up the protocol factory form the --proto option
+# set up the protocol factory form the --protocol option
pfactory_cls = PROT_FACTORIES.get(options.proto, None)
if pfactory_cls is None:
- raise AssertionError('Unknown --proto option: %s' % options.proto)
+ raise AssertionError('Unknown --protocol option: %s' % options.proto)
pfactory = pfactory_cls()
# get the server type (TSimpleServer, TNonblockingServer, etc...)
@@ -214,14 +216,26 @@
sys.exit(0)
# set up server transport and transport factory
+
+script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
+rel_path = "../keys/server.pem"
+abs_key_path = os.path.join(script_dir, rel_path)
+
host = None
if options.ssl:
from thrift.transport import TSSLSocket
- transport = TSSLSocket.TSSLServerSocket(host, options.port, certfile='../keys/server.pem')
+ transport = TSSLSocket.TSSLServerSocket(host, options.port, certfile=abs_key_path)
else:
transport = TSocket.TServerSocket(host, options.port)
tfactory = TTransport.TBufferedTransportFactory()
-
+if options.trans == 'buffered':
+ tfactory = TTransport.TBufferedTransportFactory()
+elif options.trans == 'framed':
+ tfactory = TTransport.TFramedTransportFactory()
+elif options.trans == '':
+ raise AssertionError('Unknown --transport option: %s' % options.trans)
+else:
+ tfactory = TTransport.TBufferedTransportFactory()
# if --zlib, then wrap server transport, and use a different transport factory
if options.zlib:
transport = TZlibTransport.TZlibTransport(transport) # wrap with zlib
diff --git a/test/test.sh b/test/test.sh
index c25a5d6..0fdb0de 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -31,7 +31,7 @@
BASEDIR=$(pwd)
print_header() {
- printf "%-16s %-11s %-17s %-s\n" "client-server:" "protocol:" "transport:" "result:"
+ printf "%-16s %-13s %-17s %-s\n" "client-server:" "protocol:" "transport:" "result:"
}
STATUS_HTML="status.html"
@@ -116,7 +116,7 @@
testname=${client_server}_${protocol}_${transport}
server_timeout=$(echo "(${server_startup_time}+${client_timeout})" | bc)
- printf "%-16s %-11s %-17s" ${client_server} ${protocol} ${transport}
+ printf "%-16s %-13s %-17s" ${client_server} ${protocol} ${transport}
timeout $server_timeout $server_exec > log/${testname}_server.log 2>&1 &
server_pid=$!
@@ -183,7 +183,6 @@
cpp_transports="buffered framed http"
java_server_transports="buffered framed fastframed"
java_client_transports=${java_server_transports}" http"
-# we need a test certificate first
cpp_sockets="ip domain ip-ssl"
java_sockets="ip ip-ssl"
# TODO fastframed java transport is another implementation of framed transport
@@ -197,8 +196,8 @@
csharp_sockets="ip ip-ssl"
py_protocols="binary compact json accel"
-py_transports="buffered"
-py_sockets="ip"
+py_transports="buffered framed"
+py_sockets="ip ip-ssl"
######### java client - java server #############
@@ -363,13 +362,30 @@
"ip-ssl" ) extraparam="--ssl";;
esac
do_test "py-py" "${proto}" "${trans}-${sock}" \
- "py/TestClient.py --proto=${proto} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
- "py/TestServer.py --proto=${proto} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "py/TestClient.py --protocol=${proto} --transport={trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "py/TestServer.py --protocol=${proto} --transport={trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
"10" "2"
done
done
done
+for trans in ${py_transports}; do
+ for sock in ${py_sockets}; do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "py-py" "accel-binary" "${trans}-${sock}" \
+ "py/TestClient.py --protocol=accel --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "py/TestServer.py --protocol=binary --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "10" "2"
+ do_test "py-py" "binary-accel" "${trans}-${sock}" \
+ "py/TestClient.py --protocol=binary --transport={trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "py/TestServer.py --protocol=accel --transport={trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "10" "2"
+ done
+ done
+
######### py client - cpp server ##############
for proto in $(intersection "${cpp_protocols}" "${py_protocols}"); do
for trans in $(intersection "${cpp_transports}" "${py_transports}"); do
@@ -379,13 +395,26 @@
"ip-ssl" ) extraparam="--ssl";;
esac
do_test "py-cpp" "${proto}" "${trans}-${sock}" \
- "py/TestClient.py --proto=${proto} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "py/TestClient.py --protocol=${proto} --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
"cpp/TestServer --protocol=${proto} --transport=${trans} ${extraparam}" \
"10" "2"
done
done
done
+for trans in $(intersection "${cpp_transports}" "${py_transports}"); do
+ for sock in $(intersection "${cpp_sockets}" "${py_sockets}"); do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "py-cpp" "accel-binary" "${trans}-${sock}" \
+ "py/TestClient.py --protocol=accel --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "cpp/TestServer --protocol=binary --transport=${trans} ${extraparam}" \
+ "10" "2"
+ done
+ done
+
######### cpp client - py server ##############
for proto in $(intersection "${cpp_protocols}" "${py_protocols}"); do
for trans in $(intersection "${cpp_transports}" "${py_transports}"); do
@@ -396,12 +425,25 @@
esac
do_test "cpp-py" "${proto}" "${trans}-${sock}" \
"cpp/TestClient --protocol=${proto} --transport=${trans} ${extraparam}" \
- "py/TestServer.py --proto=${proto} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "py/TestServer.py --protocol=${proto} --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
"10" "2"
done
done
done
+for trans in $(intersection "${cpp_transports}" "${py_transports}"); do
+ for sock in $(intersection "${cpp_sockets}" "${py_sockets}"); do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "cpp-py" "binary-accel" "${trans}-${sock}" \
+ "cpp/TestClient --protocol=binary --transport=${trans} ${extraparam}" \
+ "py/TestServer.py --protocol=accel --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "10" "2"
+ done
+ done
+
######### py client - java server ##############
##
for proto in $(intersection "${py_protocols}" "${java_protocols}"); do
@@ -412,13 +454,26 @@
"ip-ssl" ) extraparam="--ssl";;
esac
do_test "py-java" "${proto}" "${trans}-${sock}" \
- "py/TestClient.py --proto=${proto} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "py/TestClient.py --protocol=${proto} --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
"ant -f ../lib/java/build.xml -Dno-gen-thrift=\"\" -Dtestargs \"--protocol=${proto} --transport=${trans} ${extraparam}\" run-testserver" \
"15" "2"
done
done
done
+for trans in $(intersection "${py_transports}" "${java_server_transports}"); do
+ for sock in $(intersection "${py_sockets}" "${java_sockets}"); do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "py-java" "accel-binary" "${trans}-${sock}" \
+ "py/TestClient.py --protocol=accel --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "ant -f ../lib/java/build.xml -Dno-gen-thrift=\"\" -Dtestargs \"--protocol=binary --transport=${trans} ${extraparam}\" run-testserver" \
+ "15" "2"
+ done
+ done
+
######### java client - py server ##############
for proto in $(intersection "${py_protocols}" "${java_protocols}"); do
for trans in $(intersection "${py_transports}" "${java_client_transports}"); do
@@ -429,12 +484,25 @@
esac
do_test "java-py" "${proto}" "${trans}-${sock}" \
"ant -f ../lib/java/build.xml -Dno-gen-thrift=\"\" -Dtestargs \"--protocol=${proto} --transport=${trans} ${extraparam}\" run-testclient" \
- "py/TestServer.py --proto=${proto} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "py/TestServer.py --protocol=${proto} --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
"10" "5"
done
done
done
+for trans in $(intersection "${py_transports}" "${java_client_transports}"); do
+ for sock in $(intersection "${py_sockets}" "${java_sockets}"); do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "java-py" "binary-accel" "${trans}-${sock}" \
+ "ant -f ../lib/java/build.xml -Dno-gen-thrift=\"\" -Dtestargs \"--protocol=binary --transport=${trans} ${extraparam}\" run-testclient" \
+ "py/TestServer.py --protocol=accel --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "10" "5"
+ done
+ done
+
######### py client - nodejs server ##############
##
for proto in $(intersection "${py_protocols}" "${nodejs_protocols}"); do
@@ -445,13 +513,26 @@
"ip-ssl" ) extraparam="--ssl";;
esac
do_test "py-nodejs" "${proto}" "${trans}-${sock}" \
- "py/TestClient.py --proto=${proto} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "py/TestClient.py --protocol=${proto} --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
"node ${NODE_TEST_DIR}/server.js -p ${proto} -t ${trans} ${extraparam}" \
"15" "2"
done
done
done
+for trans in $(intersection "${py_transports}" "${nodejs_transports}"); do
+ for sock in $(intersection "${py_sockets}" "${nodejs_sockets}"); do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "py-nodejs" "${proto}" "${trans}-${sock}" \
+ "py/TestClient.py --protocol=accel --transport=${trans} --port=9090 --host=localhost --genpydir=py/gen-py ${extraparam}" \
+ "node ${NODE_TEST_DIR}/server.js -p binary -t ${trans} ${extraparam}" \
+ "15" "2"
+ done
+ done
+
######### nodejs client - py server ##############
for proto in $(intersection "${py_protocols}" "${nodejs_protocols}"); do
for trans in $(intersection "${py_transports}" "${nodejs_transports}"); do
@@ -462,12 +543,25 @@
esac
do_test "nodejs-py" "${proto}" "${trans}-${sock}" \
"node ${NODE_TEST_DIR}/client.js -p ${proto} -t ${trans} ${extraparam}" \
- "py/TestServer.py --proto=${proto} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "py/TestServer.py --protocol=${proto} --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
"10" "2"
done
done
done
+for trans in $(intersection "${py_transports}" "${nodejs_transports}"); do
+ for sock in $(intersection "${py_sockets}" "${nodejs_sockets}"); do
+ case "$sock" in
+ "ip" ) extraparam="";;
+ "ip-ssl" ) extraparam="--ssl";;
+ esac
+ do_test "nodejs-py" "binary-accel" "${trans}-${sock}" \
+ "node ${NODE_TEST_DIR}/client.js -p binary -t ${trans} ${extraparam}" \
+ "py/TestServer.py --protocol=accel --transport=${trans} --port=9090 --genpydir=py/gen-py TSimpleServer ${extraparam}" \
+ "10" "2"
+ done
+ done
+
# delete Unix Domain Socket used by cpp tests
rm -f /tmp/ThriftTest.thrift