File indexing completed on 2024-05-12 05:26:26
0001 #!/usr/bin/python3 0002 0003 import subprocess 0004 import shlex 0005 import os 0006 import sys 0007 import signal 0008 import datetime 0009 from threading import Timer 0010 import time 0011 0012 def execute(cmd): 0013 print (str(datetime.datetime.now()) + " Running command: ", cmd) 0014 popen = subprocess.Popen(shlex.split(cmd), universal_newlines=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) 0015 (stdoutdata, stderrdata) = popen.communicate() 0016 if popen.returncode: 0017 raise Exception("Something went wrong while running the command:", popen.returncode) 0018 return stdoutdata 0019 0020 def run(cmd, printOutput = False): 0021 execute(cmd) 0022 0023 def loadtest(): 0024 resourceName = "kolabnowImap" 0025 run("sinksh create resource type sink.imap identifier {} server imaps://imap.kolabnow.com:993 username test1@kolab.org".format(resourceName)) 0026 run("sinksh clear {}".format(resourceName)) 0027 run("sinksh sync folder {} --password Welcome2KolabSystems".format(resourceName), printOutput = True) 0028 0029 try: 0030 proc = subprocess.Popen(shlex.split("sinksh livequery mail --resource {}".format(resourceName))) 0031 0032 run("sinksh sync mail {}/INBOX --password Welcome2KolabSystems".format(resourceName), printOutput = True) 0033 0034 finally: 0035 proc.terminate() 0036 proc.communicate() 0037 #returncode -15 means signal 15 has terminated the process 0038 sig = -proc.returncode 0039 if sig != signal.SIGTERM: 0040 if sig == signal.SIGINT: 0041 raise KeyboardInterrupt() 0042 else: 0043 raise Exception("Something went wrong during the query: ", proc.returncode) 0044 0045 def timeout(): 0046 # This is not an error 0047 print("Exceeded runtime. Test successfully completed.") 0048 sys.stdout.flush() 0049 os._exit(0) 0050 0051 def executionTimeout(): 0052 print("Closed because execution timed out") 0053 sys.stdout.flush() 0054 os._exit(1) 0055 0056 try: 0057 runtime = 30 * 60 0058 executionTimeoutTime = 120 0059 t = Timer(runtime, timeout) 0060 t.start() 0061 start = time.time() 0062 while True: 0063 executionTimer = Timer(executionTimeoutTime, executionTimeout) 0064 executionTimer.start() 0065 loadtest(); 0066 executionTimer.cancel() 0067 print("Running for ", time.time() - start) 0068 except (KeyboardInterrupt, SystemExit): 0069 print("Aborted with Ctrl-c") 0070 sys.exit(0)