示例#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 = Pool(w)
     pool.create(w)
示例#2
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 = Pool(w)
     pool.create(w)
示例#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 = []
        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 = 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)
示例#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 = 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)
 def test_Pool_crate_threaded(self):
     w = Mock()
     w.pool_cls = Mock()
     w.use_eventloop = False
     pool = Pool(w)
     pool.create(w)
示例#6
0
 def test_Pool_crate_threaded(self):
     w = Mock()
     w.pool_cls = Mock()
     w.use_eventloop = False
     pool = Pool(w)
     pool.create(w)