Exemplo n.º 1
0
 def test_Pool_crate_threaded(self):
     w = Mock()
     w._conninfo.connection_errors = w._conninfo.channel_errors = ()
     w.pool_cls = Mock()
     w.use_eventloop = False
     pool = components.Pool(w)
     pool.create(w)
Exemplo n.º 2
0
    def test_Pool_create(self):
        from kombu. async .semaphore import LaxBoundedSemaphore
        w = Mock()
        w._conninfo.connection_errors = w._conninfo.channel_errors = ()
        w.hub = Mock()

        PoolImp = Mock()
        poolimp = PoolImp.return_value = Mock()
        poolimp._pool = [Mock(), Mock()]
        poolimp._cache = {}
        poolimp._fileno_to_inq = {}
        poolimp._fileno_to_outq = {}

        from celery.concurrency.prefork import TaskPool as _TaskPool

        class MockTaskPool(_TaskPool):
            Pool = PoolImp

            @property
            def timers(self):
                return {Mock(): 30}

        w.pool_cls = MockTaskPool
        w.use_eventloop = True
        w.consumer.restart_count = -1
        pool = components.Pool(w)
        pool.create(w)
        pool.register_with_event_loop(w, w.hub)
        if sys.platform != 'win32':
            self.assertIsInstance(w.semaphore, LaxBoundedSemaphore)
            P = w.pool
            P.start()
Exemplo n.º 3
0
    def test_Pool_create(self):
        from celery.worker.hub import BoundedSemaphore
        w = Mock()
        w._conninfo.connection_errors = w._conninfo.channel_errors = ()
        w.hub = Mock()
        w.hub.on_init = []

        PoolImp = Mock()
        poolimp = PoolImp.return_value = Mock()
        poolimp._pool = [Mock(), Mock()]
        poolimp._cache = {}
        poolimp._fileno_to_inq = {}
        poolimp._fileno_to_outq = {}

        from celery.concurrency.processes import TaskPool as _TaskPool

        class MockTaskPool(_TaskPool):
            Pool = PoolImp

            @property
            def timers(self):
                return {Mock(): 30}

        w.pool_cls = MockTaskPool
        w.use_eventloop = True
        w.consumer.restart_count = -1
        pool = components.Pool(w)
        pool.create(w)
        self.assertIsInstance(w.semaphore, BoundedSemaphore)
        self.assertTrue(w.hub.on_init)
        P = w.pool
        P.start()

        hub = Mock()
        w.hub.on_init[0](hub)

        w = Mock()
        poolimp.on_process_up(w)
        hub.add.assert_has_calls([
            call(w.sentinel, P.maintain_pool, READ | ERR),
            call(w.outqR_fd, P.handle_result_event, READ | ERR),
        ])

        poolimp.on_process_down(w)
        hub.remove.assert_has_calls([
            call(w.sentinel), call(w.outqR_fd),
        ])

        result = Mock()
        poolimp.on_timeout_cancel(result)
        poolimp.on_timeout_cancel(result)  # no more tref

        with self.assertRaises(WorkerLostError):
            P._pool.did_start_ok = Mock()
            P._pool.did_start_ok.return_value = False
            w.consumer.restart_count = 0
            P.on_poll_init(w, hub)
Exemplo n.º 4
0
    def test_Pool_create(self):
        from celery.worker.hub import BoundedSemaphore
        w = Mock()
        w._conninfo.connection_errors = w._conninfo.channel_errors = ()
        w.hub = Mock()
        w.hub.on_init = []
        w.pool_cls = Mock()
        P = w.pool_cls.return_value = Mock()
        P.timers = {Mock(): 30}
        w.use_eventloop = True
        w.consumer.restart_count = -1
        pool = components.Pool(w)
        pool.create(w)
        self.assertIsInstance(w.semaphore, BoundedSemaphore)
        self.assertTrue(w.hub.on_init)

        hub = Mock()
        w.hub.on_init[0](hub)

        cbs = w.pool.init_callbacks.call_args[1]
        w = Mock()
        cbs['on_process_up'](w)
        hub.add_reader.assert_called_with(w.sentinel, P.maintain_pool)

        cbs['on_process_down'](w)
        hub.remove.assert_called_with(w.sentinel)

        result = Mock()
        tref = result._tref

        cbs['on_timeout_cancel'](result)
        tref.cancel.assert_called_with()
        cbs['on_timeout_cancel'](result)  # no more tref

        cbs['on_timeout_set'](result, 10, 20)
        tsoft, callback = hub.timer.apply_after.call_args[0]
        callback()

        cbs['on_timeout_set'](result, 10, None)
        tsoft, callback = hub.timer.apply_after.call_args[0]
        callback()
        cbs['on_timeout_set'](result, None, 10)
        cbs['on_timeout_set'](result, None, None)

        with self.assertRaises(WorkerLostError):
            P.did_start_ok.return_value = False
            w.consumer.restart_count = 0
            pool.on_poll_init(P, w, hub)
Exemplo n.º 5
0
 def test_Pool_pool_no_sem(self):
     w = Mock()
     w.pool_cls.uses_semaphore = False
     components.Pool(w).create(w)
     assert w.process_task is w._process_task
Exemplo n.º 6
0
 def test_Pool_crate_threaded(self):
     w = Mock()
     w.pool_cls = Mock()
     w.use_eventloop = False
     pool = components.Pool(w)
     pool.create(w)