def test_run_multiple_top_level_seqs(): assert len(get_scheduler()._task_dict) == 0 for func, params, expected in run_tests: actual = realtimesequencetools.run_py_as_rtseq(func) assert actual == expected # check that the scheduler is empty after every run. assert len(get_scheduler()._task_dict) == 0
def test_run_multiple_top_level_seqs_in_parallel(): assert len(get_scheduler()._task_dict) == 0 threads = list() thread_results = dict() for func, params, expected in run_tests: thread_results[func] = expected def run_func_helper(func): actual = func() thread_results[func] = (thread_results[func], actual) thread = threading.Thread(target=run_func_helper, name=func.__name__, args=(func, )) threads.append(thread) for thread in threads: thread.start() for thread in threads: thread.join() for func, results in thread_results.items(): # results[1] is actual, results[0] is expected assert results[1] == results[ 0], "Func: %s failed assert" % func.__name__ assert len(get_scheduler()._task_dict) == 0
def test_run_multiple_top_level_seqs(): assert len(get_scheduler()._task_dict) == 0 for func, params, expected in run_tests: actual = func(*params) assert actual == expected # check that there are no tasks left to run assert len(get_scheduler()._task_dict) == 0
def ret_func(*args, **kwargs): is_top_level = False this_task = get_scheduler().try_get_task_for_curr_thread() if this_task is None: is_top_level = True this_task = get_scheduler().create_and_register_task_for_top_level( ) get_scheduler().sched() this_task.wait_for_turn() try: if is_top_level: from niveristand.clientapi import RealTimeSequence RealTimeSequence(func) retval = func(*args, **kwargs) except errors.SequenceError: # generate error already saved this error in the task, so we can just pass. pass finally: if is_top_level: this_task.mark_stopped() this_task.iteration_counter.finished = True nivs_yield() if this_task.error and this_task.error.should_raise: raise errors.RunError.RunErrorFactory(this_task.error) return retval
def iteration(): """ Returns the number of iterations since the current top-level sequence started. Returns: int: iteration count. """ from niveristand.library._tasks import get_scheduler return get_scheduler().get_task_for_curr_thread().iteration_counter.count
def generate_error(code, message, action): """ Generates an error to report test failure. Args: code(int): error code to display. message(str): error string to display. action(:class:`niveristand.clientapi.ErrorAction`): action to perform. Returns: If action is Continue, returns the generated error. """ from niveristand.clientapi._realtimesequencedefinitionapi.erroraction import ErrorAction from niveristand import errors from niveristand.library._tasks import get_scheduler assert isinstance(action, ErrorAction) error = errors.SequenceError(code, message, action) get_scheduler().get_task_for_curr_thread().error = error if action is ErrorAction.ContinueSequenceExecution: return error else: raise error