THRIFT-2578 Moving 'make cross' from test.sh to test.py

Patch: Chamila Dilshan Wijayarathna
diff --git a/test/rb/integration/TestClient.rb b/test/rb/integration/TestClient.rb
old mode 100644
new mode 100755
index f3450db..41625a8
--- a/test/rb/integration/TestClient.rb
+++ b/test/rb/integration/TestClient.rb
@@ -1,3 +1,5 @@
+#!/usr/bin/env ruby
+
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements. See the NOTICE file
diff --git a/test/rb/integration/TestServer.rb b/test/rb/integration/TestServer.rb
index 8ae2e20..3e365ca 100755
--- a/test/rb/integration/TestServer.rb
+++ b/test/rb/integration/TestServer.rb
@@ -1,3 +1,5 @@
+#!/usr/bin/env ruby
+
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements. See the NOTICE file
diff --git a/test/test.py b/test/test.py
index 30c1476..0111a2f 100755
--- a/test/test.py
+++ b/test/test.py
@@ -27,6 +27,8 @@
 import os
 import signal
 import json
+import shutil
+import threading
 from optparse import OptionParser
 
 parser = OptionParser()
@@ -44,7 +46,7 @@
 def relfile(fname):
     return os.path.join(os.path.dirname(__file__), fname)
 
-def runServiceTest(server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, port, use_zlib, use_ssl):
+def runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, port, use_zlib, use_ssl):
   # Build command line arguments
   server_args = [relfile(server_executable)]
   cli_args = [relfile(client_executable)]
@@ -63,12 +65,14 @@
 
   server_args.extend(server_extra_args)
   cli_args.extend(client_extra_args)
+  server_log=open("log/" + test_name + "_server.log","a")
+  client_log=open("log/" + test_name + "_client.log","a")
 
   if options.verbose > 0:
     print 'Testing server: %s' % (' '.join(server_args))
-    serverproc = subprocess.Popen(server_args)  
+    serverproc = subprocess.Popen(server_args, stdout=server_log, stderr=server_log)
   else:
-    serverproc = subprocess.Popen(server_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    serverproc = subprocess.Popen(server_args, stdout=server_log, stderr=server_log)
   
   def ensureServerAlive():
     if serverproc.poll() is not None:
@@ -94,17 +98,32 @@
     sock.close()
 
   try:
-    if options.verbose > 0:
-      print 'Testing client: %s' % (' '.join(cli_args))
-      ret = subprocess.call(cli_args)
-    else:
-      ret = subprocess.call(cli_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    o = []
+    def target():
+      if options.verbose > 0:
+        print 'Testing client: %s' % (' '.join(cli_args))
+        process = subprocess.Popen(cli_args, stdout=client_log, stderr=client_log)
+        o.append(process)
+        process.communicate()
+      else:
+        process = subprocess.Popen(cli_args, stdout=client_log, stderr=client_log)
+        o.append(process)
+        process.communicate()
+    thread = threading.Thread(target=target)
+    thread.start()
+
+    thread.join(10)
+    if thread.is_alive():
+      print 'Terminating process'
+      o[0].terminate()
+      thread.join()
+    ret = o[0].returncode
     if ret != 0:
       return "Client subprocess failed, retcode=%d, args: %s" % (ret, ' '.join(cli_args))
       #raise Exception("Client subprocess failed, retcode=%d, args: %s" % (ret, ' '.join(cli_args)))
   finally:
     # check that server didn't die
-    ensureServerAlive()
+    #ensureServerAlive()
     extra_sleep = 0
     if extra_sleep > 0 and options.verbose > 0:
       print ('Giving (protocol=%s,zlib=%s,ssl=%s) an extra %d seconds for child'
@@ -113,39 +132,56 @@
       time.sleep(extra_sleep)
     os.kill(serverproc.pid, signal.SIGKILL)
     serverproc.wait()
+  client_log.flush()
+  server_log.flush()
+  client_log.close()
+  server_log.close()
 
 test_count = 0
 failed = 0
 
+if os.path.exists('log'): shutil.rmtree('log')
+os.makedirs('log')
+
 with open('tests.json') as data_file:    
     data = json.load(data_file)
 
+#subprocess.call("export NODE_PATH=../lib/nodejs/test:../lib/nodejs/lib:${NODE_PATH}")
+
 for server in data["server"]:
   server_executable = server["executable"]
   server_extra_args = ""
+  server_lib = server["lib"]
   if "extra_args" in server:
     server_extra_args = server["extra_args"]
   for protocol in server["protocols"]:
     for transport in server["transports"]:
-      for client in data["client"]:
-        client_executable = client["executable"]
-        client_extra_args = ""
-        if "extra_args" in client:
-          client_extra_args = client["extra_args"]
-        if protocol in client["protocols"]:
-          if transport in client["transports"]:
-            ret = runServiceTest(server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, 9090, 0, 0)
-            if ret != None:
-              failed += 1
-              print "Error: %s" % ret
-              print "Using"   
-              print (' Server: %s --protocol=%s --transport=%s %s'
-                % (server_executable, protocol, transport, ' '.join(server_extra_args)))
-              print (' Client: %s --protocol=%s --transport=%s %s'
-                % (client_executable, protocol, transport, ''.join(client_extra_args)))
+      for sock in server["sockets"]:
+        for client in data["client"]:
+          client_executable = client["executable"]
+          client_extra_args = ""
+          client_lib = client["lib"]
+          if "extra_args" in client:
+            client_extra_args = client["extra_args"]
+          if protocol in client["protocols"]:
+            if transport in client["transports"]:
+              if sock in client["sockets"]:
+                test_name = server_lib + "_" + client_lib + "_" + protocol + "_" + transport + "_" + sock
+                ssl = 0
+                if sock == 'ip-ssl':
+                  ssl = 1
+                ret = runServiceTest(test_name, server_executable, server_extra_args, client_executable, client_extra_args, protocol, transport, 9090, 0, ssl)
+                if ret != None:
+                  failed += 1
+                  print "Error: %s" % ret
+                  print "Using"
+                  print (' Server: %s --protocol=%s --transport=%s %s'
+                    % (server_executable, protocol, transport, ' '.join(server_extra_args)))
+                  print (' Client: %s --protocol=%s --transport=%s %s'
+                    % (client_executable, protocol, transport, ''.join(client_extra_args)))
 
 
-            test_count += 1
+                test_count += 1
 
 print '%s failed of %s tests in total' % (failed, test_count)
 
diff --git a/test/tests.json b/test/tests.json
index 4ab8a9d..b5cab60 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -8,11 +8,16 @@
             "protocols": [
                 "binary",
                 "compact",
-                "json"
+                "json",
+                "accel"
             ],
             "transports": [
                 "buffered",
                 "framed"
+            ],
+            "sockets": [
+                "ip",
+                "ip-ssl"
             ]
         },
         {
@@ -28,6 +33,46 @@
                 "buffered",
                 "framed",
                 "http"
+            ],
+            "sockets": [
+                "ip",
+                "ip-ssl"
+            ]
+        },
+        {
+            "description": "Nodejs TestClient",
+            "lib": "nodejs",
+            "executable": "../lib/nodejs/test/client.js",
+            "protocols": [
+                "binary",
+                "compact",
+                "json"
+            ],
+            "transports": [
+                "buffered",
+                "framed"
+            ],
+            "sockets": [
+                "ip",
+                "ip-ssl"
+            ]
+        },
+        {
+            "description": "Ruby TestClient",
+            "lib": "ruby",
+            "executable": "rb/integration/TestClient.rb",
+            "protocols": [
+                "binary",
+                "compact",
+                "json",
+                "accel"
+            ],
+            "transports": [
+                "buffered",
+                "framed"
+            ],
+            "sockets": [
+                "ip"
             ]
         }
     ],
@@ -41,11 +86,16 @@
             "protocols": [
                 "binary",
                 "compact",
-                "json"
+                "json",
+                "accel"
             ],
             "transports": [
                 "buffered",
                 "framed"
+            ],
+            "sockets": [
+                "ip",
+                "ip-ssl"
             ]
         },
         {
@@ -61,6 +111,46 @@
                 "buffered",
                 "framed",
                 "http"
+            ],
+            "sockets": [
+                "ip",
+                "ip-ssl"
+            ]
+        },
+        {
+            "description": "Ruby TestServer",
+            "lib": "ruby",
+            "executable": "rb/integration/TestServer.rb",
+            "protocols": [
+                "binary",
+                "compact",
+                "json",
+                "accel"
+            ],
+            "transports": [
+                "buffered",
+                "framed"
+            ],
+            "sockets": [
+                "ip"
+            ]
+        },
+        {
+            "description": "Nodejs TestServer",
+            "lib": "nodejs",
+            "executable": "../lib/nodejs/test/server.js",
+            "protocols": [
+                "binary",
+                "compact",
+                "json"
+            ],
+            "transports": [
+                "buffered",
+                "framed"
+            ],
+            "sockets": [
+                "ip",
+                "ip-ssl"
             ]
         }
     ]