示例#1
0
 def test_create_when_eventloop(self):
     w = Mock()
     w.use_eventloop = w.pool_putlocks = w.pool_cls.uses_semaphore = True
     comp = Pool(w)
     w.pool = Mock()
     comp.create(w)
     assert w.process_task is w._process_task_sem
示例#2
0
 def test_create_when_eventloop(self):
     w = Mock()
     w.use_eventloop = w.pool_putlocks = w.pool_cls.uses_semaphore = True
     comp = Pool(w)
     w.pool = Mock()
     comp.create(w)
     self.assertIs(w.process_task, w._process_task_sem)
示例#3
0
 def test_create_when_eventloop(self):
     if IS_WINDOWS:
         raise SkipTest('Win32')
     w = Mock()
     w.use_eventloop = w.pool_putlocks = w.pool_cls.uses_semaphore = True
     comp = Pool(w)
     w.pool = Mock()
     comp.create(w)
     self.assertIs(w.process_task, w._process_task_sem)
示例#4
0
 def test_create_when_eventloop(self):
     if IS_WINDOWS:
         raise SkipTest('Win32')
     w = Mock()
     w.use_eventloop = w.pool_putlocks = w.pool_cls.uses_semaphore = True
     comp = Pool(w)
     w.pool = Mock()
     comp.create(w)
     self.assertIs(w.process_task, w._process_task_sem)
示例#5
0
    def test_create_calls_instantiate_with_max_memory(self):
        w = Mock()
        w.use_eventloop = w.pool_putlocks = w.pool_cls.uses_semaphore = True
        comp = Pool(w)
        comp.instantiate = Mock()
        w.max_memory_per_child = 32

        comp.create(w)

        assert comp.instantiate.call_args[1]['max_memory_per_child'] == 32
示例#6
0
    def test_create_calls_instantiate_with_max_memory(self):
        w = Mock()
        w.use_eventloop = w.pool_putlocks = w.pool_cls.uses_semaphore = True
        comp = Pool(w)
        comp.instantiate = Mock()
        w.max_memory_per_child = 32

        comp.create(w)

        assert comp.instantiate.call_args[1]['max_memory_per_child'] == 32
示例#7
0
    def test_close_terminate(self):
        w = Mock()
        comp = Pool(w)
        pool = w.pool = Mock()
        comp.close(w)
        pool.close.assert_called_with()
        comp.terminate(w)
        pool.terminate.assert_called_with()

        w.pool = None
        comp.close(w)
        comp.terminate(w)
示例#8
0
    def test_close_terminate(self):
        w = Mock()
        comp = Pool(w)
        pool = w.pool = Mock()
        comp.close(w)
        pool.close.assert_called_with()
        comp.terminate(w)
        pool.terminate.assert_called_with()

        w.pool = None
        comp.close(w)
        comp.terminate(w)
示例#9
0
    def test_Pool_create(self):
        from celery.worker.hub import BoundedSemaphore

        w = Mock()
        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
        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)

        P.did_start_ok.return_value = False
        with self.assertRaises(WorkerLostError):
            pool.on_poll_init(P, hub)
示例#10
0
    def test_Pool_create(self):
        from celery.worker.hub import BoundedSemaphore
        w = Mock()
        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
        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)

        P.did_start_ok.return_value = False
        with self.assertRaises(WorkerLostError):
            pool.on_poll_init(P, hub)
示例#11
0
 def test_Pool_crate_threaded(self):
     w = Mock()
     w.pool_cls = Mock()
     w.use_eventloop = False
     pool = Pool(w)
     pool.create(w)
示例#12
0
 def test_Pool_crate_threaded(self):
     w = Mock()
     w.pool_cls = Mock()
     w.use_eventloop = False
     pool = Pool(w)
     pool.create(w)