示例#1
0
def main():
    tasks = (
        Task(taskid='single letter', testscript='tasks.py', foo='f', bar='b'),
        Task(taskid='single number', testscript='tasks.py', foo='2', bar='5'),
        Task(taskid='long string',
             testscript='tasks.py',
             foo='dfgdf',
             bar='mnfgbgfnbghn'),
        Task(taskid='long numbers', testscript='tasks.py', foo='555',
             bar='34'),
        Task(taskid='empty data', testscript='tasks.py', foo='', bar=''),
    )

    for task in tasks:
        task.start()
        task.join()
示例#2
0
def new_task(runtime, test, num1, num2):
    return Task(testscript=test, runtime=runtime, num1=num1, num2=num2)
示例#3
0
def main():
    # Find the location of the script in relation to the job file
    test_path = os.path.dirname(os.path.abspath(__file__))
    testscript = os.path.join(test_path, 'task_example.py')

    # create two tasks. for simplicity's sake, we'll reuse the same script
    task_1 = Task(testscript = testscript)
    task_2 = Task(testscript = testscript)

    # start both tasks together (async execution)
    task_1.start()
    task_2.start()

    # wait for tasks to finish before terminating
    task_1.wait()
    task_2.wait()
示例#4
0
def new_task(runtime, duration):
    return Task(testscript='arguments.py', runtime=runtime, duration=duration, interval=10)
示例#5
0
def main(runtime):
    parser = argparse.ArgumentParser(description='Parser for two numbers')
    parser.add_argument('-a', type = float, dest = 'a', default = 1, required = False, help = 'You must enter number for correct test')
    parser.add_argument('-b', type = float, dest = 'b', default = 1, required = False, help = 'You must enter number for correct test')
    args, sys.argv[1:] = parser.parse_known_args(sys.argv[1:0])

    task_1 = Task(testscript ='add_func.py',
                  taskid = 'add_func_task',
                  runtime=runtime,
                  a = args.a, b = args.b)

    task_2 = Task(testscript = 'div_func.py',
                  taskid = 'div_func_task',
                  runtime=runtime,
                  a = args.a, b = args.b)

    task_3 = Task(testscript = 'mult_func.py',
                  taskid = 'mult_func_test',
                  runtime=runtime,
                  a = args.a, b = args.b)

    task_4 = Task(testscript = 'substract_func.py',
                  taskid = 'substract_func_py',
                  runtime=runtime,
                  a = args.a, b = args.b)

    task_1.start()
    task_2.start()
    task_3.start()
    task_4.start()

    all_t=[task_1, task_2, task_3, task_4]

    counter = timedelta(seconds=10)

    while counter:
        # check if processes are alive, if so, continue to wait
        if any(t.is_alive() for t in all_t):
            time.sleep(1)
            counter -= timedelta(seconds=1)
        else:
            break
    else:
        # exceeded runtime
        task_1.terminate()
        task_1.join()
        task_2.terminate()
        task_2.join()
        task_3.terminate()
        task_3.join()
        task_4.terminate()
        task_4.join()

        # raise exception
        raise TimeoutError('Not all tasks finished in 5 minutes!')


    """
def main(runtime):
    runtime.job.name = 'This is just a test.'
    task1 = Task('mytestcase.py', runtime=runtime, taskid='Testing', username=args.username, password=args.password)
    task1.start()
    task1.join()