1import sys 2import os 3import subprocess 4import shlex 5 6TIMEOUT = 100 7# Runner for elasticurl integration tests 8 9mvn_args = " ".join(map(shlex.quote, sys.argv[1:])) 10 11java_command = ['mvn', '-e', 'exec:java', '-Dexec.classpathScope=\"test\"', 12 '-Dexec.mainClass=\"software.amazon.awssdk.crt.test.Elasticurl\"', '-Dexec.args=\"{}\"'.format(mvn_args)] 13 14if os.name == 'nt': 15 # Windows uses mvn.cmd instead 16 java_command[0] = 'mvn.cmd' 17command_string = " ".join(java_command) 18 19 20def run_command(args_str): 21 print(args_str) 22 # gather all stderr and stdout to a single string that we print only if things go wrong 23 process = subprocess.Popen( 24 args_str, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) 25 timedout = False 26 try: 27 output = process.communicate(timeout=TIMEOUT)[0] 28 except subprocess.TimeoutExpired: 29 timedout = True 30 process.kill() 31 output = process.communicate()[0] 32 finally: 33 if process.returncode != 0 or timedout: 34 for line in output.splitlines(): 35 print(line.decode()) 36 if timedout: 37 raise RuntimeError("Timeout happened after {secs} secs from: {cmd}".format( 38 secs=TIMEOUT, cmd=args_str)) 39 else: 40 raise RuntimeError("Return code {code} from: {cmd}".format( 41 code=process.returncode, cmd=args_str)) 42 43 44run_command(command_string) 45