Ejemplo n.º 1
0
    def test_base(self):
        p = ThreadPool()

        # default pools have no workers - and threading was removed entirely ...
        assert p.size() == 0

        # SINGLE TASK SERIAL SYNC MODE
        ##############################
        # put a few unrelated tasks that we forget about - check ref counts and cleanup
        t1, t2 = FixtureThreadTask(iter(list()), "nothing1",
                                   None), FixtureThreadTask(
                                       iter(list()), "nothing2", None)
        urc1 = p.add_task(t1)
        urc2 = p.add_task(t2)
        assert p.num_tasks() == 2

        # test pool reader
        assert urc1.pool_ref()() is p
        assert urc1.task_ref()() is t1
        assert urc1.pool() == p
        assert urc1.task() == t1

        ## SINGLE TASK #################
        self._assert_single_task(p, False)
        if py2:
            assert p.num_tasks() == 2
        del (urc1)
        if py2:
            assert p.num_tasks() == 1

        p.remove_task(t2)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t2) == 2

        t3 = FixtureChannelThreadTask(urc2, "channel", None)
        urc3 = p.add_task(t3)
        if py2:
            assert p.num_tasks() == 1
        del (urc3)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t3) == 2

        # DEPENDENT TASKS SYNC MODE
        ###########################
        self._assert_async_dependent_tasks(p)
Ejemplo n.º 2
0
    def test_base(self):
        p = ThreadPool()

        # default pools have no workers - and threading was removed entirely ... 
        assert p.size() == 0

        # SINGLE TASK SERIAL SYNC MODE
        ##############################
        # put a few unrelated tasks that we forget about - check ref counts and cleanup
        t1, t2 = FixtureThreadTask(iter(list()), "nothing1", None), FixtureThreadTask(iter(list()), "nothing2", None)
        urc1 = p.add_task(t1)
        urc2 = p.add_task(t2)
        assert p.num_tasks() == 2

        # test pool reader
        assert urc1.pool_ref()() is p
        assert urc1.task_ref()() is t1
        assert urc1.pool() == p
        assert urc1.task() == t1

        ## SINGLE TASK #################
        self._assert_single_task(p, False)
        if py2:
            assert p.num_tasks() == 2
        del(urc1)
        if py2:
            assert p.num_tasks() == 1

        p.remove_task(t2)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t2) == 2

        t3 = FixtureChannelThreadTask(urc2, "channel", None)
        urc3 = p.add_task(t3)
        if py2:
            assert p.num_tasks() == 1
        del(urc3)
        if py2:
            assert p.num_tasks() == 0
        assert sys.getrefcount(t3) == 2


        # DEPENDENT TASKS SYNC MODE
        ###########################
        self._assert_async_dependent_tasks(p)