Esempio n. 1
0
    def command_task_run(self, args):
        """
        Runs a task from arguments

        :param args: parsed command line arguments turned into a dictionary
        :type args: dict
        """
        runnable = Runnable.from_args(args)
        task = Task(runnable,
                    args.get('identifier'),
                    args.get('status_uri', []),
                    category=args.get('category', TASK_DEFAULT_CATEGORY),
                    job_id=args.get('job_id'))
        for status in task.run():
            self.echo(status)
Esempio n. 2
0
    def from_runnable(cls, pre_runnable, status_server_uri=None, job_id=None):  # pylint: disable=W0221
        """Creates runtime task for pre_test plugin from runnable

        :param pre_runnable: the "description" of what the task should run.
        :type runnable: :class:`avocado.core.nrunner.Runnable`
        :param status_server_uri: the URIs for the status servers that this
                                  task should send updates to.
        :type status_server_uri: list
        :param job_id: the ID of the job, for authenticating messages that get
                       sent to the destination job's status server and will
                       make into the job's results.
        :type job_id: str
        :returns: RuntimeTask of the test from runnable
        """
        name = f'{pre_runnable.kind}-{pre_runnable.kwargs.get("name")}'
        prefix = 0
        # the human UI works with TestID objects, so we need to
        # use it to name Task
        task_id = TestID(prefix, name)
        # creates the dependency task
        task = Task(
            pre_runnable,
            identifier=task_id,
            status_uris=status_server_uri,
            category="pre_test",
            job_id=job_id,
        )
        return cls(task)
Esempio n. 3
0
    def command_task_run_recipe(self, args):
        """
        Runs a task from a recipe

        :param args: parsed command line arguments turned into a dictionary
        :type args: dict
        """
        task = Task.from_recipe(args.get("recipe"))
        for status in task.run():
            self.echo(status)
Esempio n. 4
0
    def from_runnable(
        cls,
        runnable,
        no_digits,
        index,
        variant,
        test_suite_name=None,
        status_server_uri=None,
        job_id=None,
    ):
        """Creates runtime task for test from runnable

        :param runnable: the "description" of what the task should run.
        :type runnable: :class:`avocado.core.nrunner.Runnable`
        :param no_digits: number of digits of the test uid
        :type no_digits: int
        :param index: index of tests inside test suite
        :type index: int
        :param test_suite_name: test suite name which this test is related to
        :type test_suite_name: str
        :param status_server_uri: the URIs for the status servers that this
                                  task should send updates to.
        :type status_server_uri: list
        :param job_id: the ID of the job, for authenticating messages that get
                       sent to the destination job's status server and will
                       make into the job's results.
        :type job_id: str
        :returns: RuntimeTask of the test from runnable
        """

        # create test ID
        if test_suite_name:
            prefix = f"{test_suite_name}-{index}"
        else:
            prefix = index
        test_id = TestID(prefix, runnable.identifier, variant, no_digits)
        # inject variant on runnable
        runnable.variant = dump_variant(variant)

        # handles the test task
        task = Task(runnable,
                    identifier=test_id,
                    status_uris=status_server_uri,
                    job_id=job_id)
        return cls(task)
Esempio n. 5
0
    def get_dependencies_form_runnable(cls,
                                       runnable,
                                       status_server_uri=None,
                                       job_id=None):
        """Creates runtime tasks for dependencies from runnable

        :param runnable: the "description" of what the task should run.
        :type runnable: :class:`avocado.core.nrunner.Runnable`
        :param status_server_uri: the URIs for the status servers that this
                                  task should send updates to.
        :type status_server_uri: list
        :param job_id: the ID of the job, for authenticating messages that get
                       sent to the destination job's status server and will
                       make into the job's results.
        :type job_id: str
        :returns: RUntimeTasks of the dependencies from runnable
        :rtype: list
        """
        if runnable.dependencies is None:
            return []

        # creates the runnables for the dependencies
        dependencies_runnables = DependencyResolver.resolve(runnable)
        dependencies_runtime_tasks = []
        # creates the tasks and runtime tasks for the dependencies
        for dependency_runnable in dependencies_runnables:
            name = (f"{dependency_runnable.kind}-"
                    f"{dependency_runnable.kwargs.get('name')}")
            prefix = 0
            # the human UI works with TestID objects, so we need to
            # use it to name Task
            task_id = TestID(prefix, name)
            # with --dry-run we don't want to run dependencies
            if runnable.kind == 'dry-run':
                dependency_runnable.kind = 'noop'
            # creates the dependency task
            dependency_task = Task(dependency_runnable,
                                   identifier=task_id,
                                   status_uris=status_server_uri,
                                   category='dependency',
                                   job_id=job_id)
            dependencies_runtime_tasks.append(cls(dependency_task))

        return dependencies_runtime_tasks
Esempio n. 6
0
    async def test(self):
        number_of_tasks = 80
        number_of_workers = 8

        runnable = Runnable("noop", "noop")
        runtime_tasks = [
            RuntimeTask(Task(runnable, "%03i" % _))  # pylint: disable=C0209
            for _ in range(1, number_of_tasks + 1)
        ]
        spawner = Spawner()
        status_repo = StatusRepo()

        state_machine = statemachine.TaskStateMachine(runtime_tasks,
                                                      status_repo)
        workers = [
            statemachine.Worker(state_machine, spawner).run()
            for _ in range(number_of_workers)
        ]

        await asyncio.gather(*workers)
        self.assertEqual(number_of_tasks, len(state_machine.finished))
Esempio n. 7
0
 def test_set_category(self):
     runnable = Runnable('noop', 'noop_uri')
     task = Task(runnable, 'task_id', category='new_category')
     self.assertEqual(task.category, 'new_category')
Esempio n. 8
0
 def test_default_category(self):
     runnable = Runnable('noop', 'noop_uri')
     task = Task(runnable, 'task_id')
     self.assertEqual(task.category, 'test')
Esempio n. 9
0
 def setUp(self):
     runnable = Runnable("noop", "uri")
     task = Task(runnable, "1")
     self.runtime_task = RuntimeTask(task)
     self.spawner = MockRandomAliveSpawner()
Esempio n. 10
0
 def setUp(self):
     runnable = Runnable("noop", "uri")
     task = Task(runnable, "1")
     self.runtime_task = RuntimeTask(task)
     self.spawner = ProcessSpawner()
Esempio n. 11
0
 def test_set_category(self):
     runnable = Runnable("noop", "noop_uri")
     task = Task(runnable, "task_id", category="new_category")
     self.assertEqual(task.category, "new_category")
Esempio n. 12
0
 def test_default_category(self):
     runnable = Runnable("noop", "noop_uri")
     task = Task(runnable, "task_id")
     self.assertEqual(task.category, "test")
Esempio n. 13
0
 def setUp(self):
     runnable = Runnable("noop", "noop")
     task = Task(runnable, "1-noop")
     self.runtime_task = RuntimeTask(task)
 def setUp(self):
     runnable = Runnable('noop', 'noop')
     task = Task(runnable, '1-noop')
     self.runtime_task = RuntimeTask(task)