Пример #1
0
def schedule_for(current_track, task, client_index):
    """
    Calculates a client's schedule for a given task.

    :param current_track: The current track.
    :param task: The task that should be executed.
    :param client_index: The current client index.  Must be in the range [0, `task.clients').
    :return: A generator for the operations the given client needs to perform for this task.
    """
    op = task.operation
    num_clients = task.clients
    target_throughput = task.target_throughput / num_clients if task.target_throughput else None
    runner_for_op = runner.runner_for(op.type)
    params_for_op = track.operation_parameters(current_track, op).partition(
        client_index, num_clients)

    if task.warmup_time_period is not None:
        logger.info(
            "Creating time period based schedule for [%s] with a warmup period of [%d] seconds."
            % (op, task.warmup_time_period))
        return time_period_based(target_throughput, task.warmup_time_period,
                                 runner_for_op, params_for_op)
    else:
        logger.info(
            "Creating iteration-count based schedule for [%s] with [%d] warmup iterations and [%d] iterations."
            % (op, task.warmup_iterations, task.iterations))
        return iteration_count_based(target_throughput,
                                     task.warmup_iterations // num_clients,
                                     task.iterations // num_clients,
                                     runner_for_op, params_for_op)
Пример #2
0
 def test_runner_function_should_be_wrapped(self):
     def runner_function(es, params):
         pass
     runner.register_runner(operation_type="unit_test", runner=runner_function)
     returned_runner = runner.runner_for("unit_test")
     self.assertIsInstance(returned_runner, runner.DelegatingRunner)
     self.assertEqual("user-defined runner for [runner_function]", repr(returned_runner))
Пример #3
0
def schedule_for(current_track, task, client_index):
    """
    Calculates a client's schedule for a given task.

    :param current_track: The current track.
    :param task: The task that should be executed.
    :param client_index: The current client index.  Must be in the range [0, `task.clients').
    :return: A generator for the operations the given client needs to perform for this task.
    """
    op = task.operation
    num_clients = task.clients
    target_throughput = task.target_throughput / num_clients if task.target_throughput else None
    runner_for_op = runner.runner_for(op.type)
    params_for_op = track.operation_parameters(current_track, op).partition(client_index, num_clients)

    if task.warmup_time_period is not None or task.time_period is not None:
        warmup_time_period = task.warmup_time_period if task.warmup_time_period else 0
        logger.info("Creating time-period based schedule for [%s] with a warmup period of [%s] seconds and a time period of [%s] seconds."
                    % (op, str(warmup_time_period), str(task.time_period)))
        return time_period_based(target_throughput, warmup_time_period, task.time_period, runner_for_op, params_for_op)
    else:
        logger.info("Creating iteration-count based schedule for [%s] with [%d] warmup iterations and [%d] iterations." %
                    (op, task.warmup_iterations, task.iterations))
        return iteration_count_based(target_throughput, task.warmup_iterations // num_clients, task.iterations // num_clients,
                                     runner_for_op, params_for_op)
Пример #4
0
    def test_runner_class_should_be_wrapped(self):
        class UnitTestRunner:
            def __call__(self, *args):
                pass

            def __str__(self):
                return "UnitTestRunner"

        test_runner = UnitTestRunner()
        runner.register_runner(operation_type="unit_test", runner=test_runner)
        returned_runner = runner.runner_for("unit_test")
        self.assertIsInstance(returned_runner, runner.DelegatingRunner)
        self.assertEqual("user-defined runner for [UnitTestRunner]", repr(returned_runner))
Пример #5
0
    def test_runner_class_with_context_manager_should_be_registered_as_is(self):
        class UnitTestRunner:
            def __enter__(self):
                return self

            def __call__(self, *args):
                pass

            def __exit__(self, exc_type, exc_val, exc_tb):
                return False

        test_runner = UnitTestRunner()
        runner.register_runner(operation_type="unit_test", runner=test_runner)
        returned_runner = runner.runner_for("unit_test")
        self.assertTrue(test_runner == returned_runner)