summaryrefslogtreecommitdiffstats
path: root/tests/sinkloadtest.py
blob: 3eff2700ac2257ff4d392089880589405ff9ae54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3

import subprocess
import shlex
import os
import sys
import signal
import datetime

def execute(cmd):
    print (str(datetime.datetime.now()) + " Running command: ", cmd)
    popen = subprocess.Popen(shlex.split(cmd), universal_newlines=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
    (stdoutdata, stderrdata) = popen.communicate()
    if popen.returncode:
        raise Exception("Something went wrong while running the command:", popen.returncode)
    return stdoutdata

def run(cmd, printOutput = False):
    execute(cmd)

def loadtest():
    resourceName = "kolabnowImap"
    run("sinksh create resource type sink.imap identifier {} server imaps://imap.kolabnow.com:993 username test1@kolab.org".format(resourceName))
    run("sinksh clear {}".format(resourceName))
    run("sinksh sync folder {} --password Welcome2KolabSystems".format(resourceName), printOutput = True)

    try:
        proc = subprocess.Popen(shlex.split("sinksh livequery mail --resource {}".format(resourceName)))

        run("sinksh sync mail {}/INBOX --password Welcome2KolabSystems".format(resourceName), printOutput = True)

    finally:
        proc.terminate()
        proc.communicate()
        #returncode -15 means signal 15 has terminated the process
        sig = -proc.returncode
        if sig != signal.SIGTERM:
            if sig == signal.SIGINT:
                raise KeyboardInterrupt()
            else:
                raise Exception("Something went wrong during the query: ", proc.returncode)

try:
    while True:
        loadtest();
except (KeyboardInterrupt, SystemExit):
    print("Aborted with Ctrl-c")
    sys.exit(0)