def test_add_main(self, proc_pool):
     """
     Test scheduling a Task from the __main__ module. This should not be
     allowed, since __main__ is a different module for the child process.
     """
     main_task = tasks.Task(target="runnable", module="__main__")
     with pytest.raises(ValueError):
         proc_pool.add(main_task, main_task.uid())
Exemplo n.º 2
0
    def test_run_task(self, proc_pool):
        """
        Test that a simple Task can be scheduled to a process pool and run.
        """
        # Create and add a basic example Task. When materialized and run,
        # the Runnable will return the product of its args: 7 * 3 => 21.
        example_task = tasks.Task(
            target='Runnable',
            module='tests.unit.testplan.runners.pools.tasks.data.sample_tasks',
            args=(7, 3))
        proc_pool.add(example_task, example_task.uid())
        with proc_pool:
            assert proc_pool.status.tag == proc_pool.status.STARTED
            while proc_pool.pending_work():
                assert proc_pool.is_alive
                time.sleep(0.2)

        assert proc_pool.status.tag == proc_pool.status.STOPPED

        # Check that the expected result is stored both on the worker and
        # on the pool's result.
        assert proc_pool.get(example_task.uid()).result == 21
        assert proc_pool.results[example_task.uid()].result == 21