コード例 #1
0
    def test_sched(self):
        with mock_module(*gevent_modules):
            with patch_many('gevent.greenlet',
                            'gevent.greenlet.GreenletExit') as (greenlet,
                                                                GreenletExit):
                greenlet.Greenlet = object
                x = Schedule()
                greenlet.Greenlet = Mock()
                x._Greenlet.spawn_later = Mock()
                x._GreenletExit = KeyError
                entry = Mock()
                g = x._enter(1, 0, entry)
                self.assertTrue(x.queue)

                x._entry_exit(g)
                g.kill.assert_called_with()
                self.assertFalse(x._queue)

                x._queue.add(g)
                x.clear()
                x._queue.add(g)
                g.kill.side_effect = KeyError()
                x.clear()

                g = x._Greenlet()
                g.cancel()
コード例 #2
0
ファイル: test_gevent.py プロジェクト: 1995rishi/flaskmap
    def test_sched(self):
        with mock_module(*gevent_modules):
            with patch_many('gevent.greenlet',
                            'gevent.greenlet.GreenletExit') as (greenlet,
                                                                GreenletExit):
                greenlet.Greenlet = object
                x = Schedule()
                greenlet.Greenlet = Mock()
                x._Greenlet.spawn_later = Mock()
                x._GreenletExit = KeyError
                entry = Mock()
                g = x._enter(1, 0, entry)
                self.assertTrue(x.queue)

                x._entry_exit(g)
                g.kill.assert_called_with()
                self.assertFalse(x._queue)

                x._queue.add(g)
                x.clear()
                x._queue.add(g)
                g.kill.side_effect = KeyError()
                x.clear()

                g = x._Greenlet()
                g.cancel()
コード例 #3
0
ファイル: test_eventlet.py プロジェクト: rodzevich/celery
 def test_pool(self):
     with mock_module(*eventlet_modules):
         with patch_many("eventlet.greenpool.GreenPool", "eventlet.greenthread") as (GreenPool, greenthread):
             x = TaskPool()
             x.on_start()
             x.on_stop()
             x.on_apply(Mock())
             x._pool = None
             x.on_stop()
             self.assertTrue(x.getpid())
コード例 #4
0
 def test_install(self):
     self.app.loader = Mock()
     with self.fixup_context(self.app) as (f, _, _):
         with patch_many("os.getcwd", "sys.path", "celery.fixups.django.signals") as (cw, p, sigs):
             cw.return_value = "/opt/vandelay"
             f.install()
             sigs.worker_init.connect.assert_called_with(f.on_worker_init)
             self.assertEqual(self.app.loader.now, f.now)
             self.assertEqual(self.app.loader.mail_admins, f.mail_admins)
             p.append.assert_called_with("/opt/vandelay")
コード例 #5
0
 def test_install(self):
     self.app.loader = Mock()
     with self.fixup_context(self.app) as (f, _, _):
         with patch_many('os.getcwd', 'sys.path',
                         'celery.fixups.django.signals') as (cw, p, sigs):
             cw.return_value = '/opt/vandelay'
             f.install()
             sigs.worker_init.connect.assert_called_with(f.on_worker_init)
             self.assertEqual(self.app.loader.now, f.now)
             self.assertEqual(self.app.loader.mail_admins, f.mail_admins)
             p.append.assert_called_with('/opt/vandelay')
コード例 #6
0
 def test_install(self):
     self.app.conf = {"CELERY_DB_REUSE_MAX": None}
     self.app.loader = Mock()
     with self.fixup_context(self.app) as (f, _, _):
         with patch_many("celery.fixups.django.signals") as (sigs,):
             f.install()
             sigs.beat_embedded_init.connect.assert_called_with(f.close_database)
             sigs.worker_ready.connect.assert_called_with(f.on_worker_ready)
             sigs.task_prerun.connect.assert_called_with(f.on_task_prerun)
             sigs.task_postrun.connect.assert_called_with(f.on_task_postrun)
             sigs.worker_process_init.connect.assert_called_with(f.on_worker_process_init)
コード例 #7
0
ファイル: test_eventlet.py プロジェクト: zhangqian2013/celery
 def test_pool(self):
     with mock_module(*eventlet_modules):
         with patch_many('eventlet.greenpool.GreenPool',
                         'eventlet.greenthread') as (GreenPool,
                                                     greenthread):
             x = TaskPool()
             x.on_start()
             x.on_stop()
             x.on_apply(Mock())
             x._pool = None
             x.on_stop()
             self.assertTrue(x.getpid())
コード例 #8
0
ファイル: test_django.py プロジェクト: anukat2015/AIR
 def test_install(self):
     self.app.conf = {'CELERY_DB_REUSE_MAX': None}
     self.app.loader = Mock()
     with self.fixup_context(self.app) as (f, _, _):
         with patch_many('celery.fixups.django.signals') as (sigs, ):
             f.install()
             sigs.beat_embedded_init.connect.assert_called_with(
                 f.close_database, )
             sigs.worker_ready.connect.assert_called_with(f.on_worker_ready)
             sigs.task_prerun.connect.assert_called_with(f.on_task_prerun)
             sigs.task_postrun.connect.assert_called_with(f.on_task_postrun)
             sigs.worker_process_init.connect.assert_called_with(
                 f.on_worker_process_init, )
コード例 #9
0
ファイル: test_django.py プロジェクト: nonoDevil/celery
 def test_install(self):
     self.app.conf = {'CELERY_DB_REUSE_MAX': None}
     self.app.loader = Mock()
     with self.fixup_context(self.app) as (f, _, _):
         with patch_many('os.getcwd', 'sys.path',
                         'celery.fixups.django.signals') as (cw, p, sigs):
             cw.return_value = '/opt/vandelay'
             f.install()
             sigs.beat_embedded_init.connect.assert_called_with(
                 f.close_database, )
             sigs.worker_ready.connect.assert_called_with(f.on_worker_ready)
             sigs.task_prerun.connect.assert_called_with(f.on_task_prerun)
             sigs.task_postrun.connect.assert_called_with(f.on_task_postrun)
             sigs.worker_init.connect.assert_called_with(f.on_worker_init)
             sigs.worker_process_init.connect.assert_called_with(
                 f.on_worker_process_init, )
             self.assertEqual(self.app.loader.now, f.now)
             self.assertEqual(self.app.loader.mail_admins, f.mail_admins)
             p.append.assert_called_with('/opt/vandelay')
コード例 #10
0
 def test_install(self):
     self.app.conf = {'CELERY_DB_REUSE_MAX': None}
     self.app.loader = Mock()
     with self.fixup_context(self.app) as (f, _, _):
         with patch_many('os.getcwd', 'sys.path',
                         'celery.fixups.django.signals') as (cw, p, sigs):
             cw.return_value = '/opt/vandelay'
             f.install()
             sigs.beat_embedded_init.connect.assert_called_with(
                 f.close_database, )
             sigs.worker_ready.connect.assert_called_with(f.on_worker_ready)
             sigs.task_prerun.connect.assert_called_with(f.on_task_prerun)
             sigs.task_postrun.connect.assert_called_with(f.on_task_postrun)
             sigs.worker_init.connect.assert_called_with(f.on_worker_init)
             sigs.worker_process_init.connect.assert_called_with(
                 f.on_worker_process_init, )
             self.assertEqual(self.app.loader.now, f.now)
             self.assertEqual(self.app.loader.mail_admins, f.mail_admins)
             p.append.assert_called_with('/opt/vandelay')
コード例 #11
0
ファイル: test_eventlet.py プロジェクト: rodzevich/celery
    def test_sched(self):
        with mock_module(*eventlet_modules):
            with patch_many("eventlet.greenthread.spawn_after", "greenlet.GreenletExit") as (spawn_after, GreenletExit):
                x = Schedule()
                x.GreenletExit = KeyError
                entry = Mock()
                g = x._enter(1, 0, entry)
                self.assertTrue(x.queue)

                x._entry_exit(g, entry)
                g.wait.side_effect = KeyError()
                x._entry_exit(g, entry)
                entry.cancel.assert_called_with()
                self.assertFalse(x._queue)

                x._queue.add(g)
                x.clear()
                x._queue.add(g)
                g.cancel.side_effect = KeyError()
                x.clear()
コード例 #12
0
ファイル: test_eventlet.py プロジェクト: zhangqian2013/celery
    def test_sched(self):
        with mock_module(*eventlet_modules):
            with patch_many('eventlet.greenthread.spawn_after',
                            'greenlet.GreenletExit') as (spawn_after,
                                                         GreenletExit):
                x = Schedule()
                x.GreenletExit = KeyError
                entry = Mock()
                g = x._enter(1, 0, entry)
                self.assertTrue(x.queue)

                x._entry_exit(g, entry)
                g.wait.side_effect = KeyError()
                x._entry_exit(g, entry)
                entry.cancel.assert_called_with()
                self.assertFalse(x._queue)

                x._queue.add(g)
                x.clear()
                x._queue.add(g)
                g.cancel.side_effect = KeyError()
                x.clear()
コード例 #13
0
ファイル: test_gevent.py プロジェクト: SalesSeek/celery
    def test_pool(self):
        with mock_module(*gevent_modules):
            with patch_many('gevent.spawn_raw', 'gevent.pool.Pool') as (
                    spawn_raw, Pool):
                x = TaskPool()
                x.on_start()
                x.on_stop()
                x.on_apply(Mock())
                x._pool = None
                x.on_stop()

                x._pool = Mock()
                x._pool._semaphore.counter = 1
                x._pool.size = 1
                x.grow()
                self.assertEqual(x._pool.size, 2)
                self.assertEqual(x._pool._semaphore.counter, 2)
                x.shrink()
                self.assertEqual(x._pool.size, 1)
                self.assertEqual(x._pool._semaphore.counter, 1)

                x._pool = [4, 5, 6]
                self.assertEqual(x.num_processes, 3)
コード例 #14
0
    def test_pool(self):
        with mock_module(*gevent_modules):
            with patch_many('gevent.spawn_raw',
                            'gevent.pool.Pool') as (spawn_raw, Pool):
                x = TaskPool()
                x.on_start()
                x.on_stop()
                x.on_apply(Mock())
                x._pool = None
                x.on_stop()

                x._pool = Mock()
                x._pool._semaphore.counter = 1
                x._pool.size = 1
                x.grow()
                self.assertEqual(x._pool.size, 2)
                self.assertEqual(x._pool._semaphore.counter, 2)
                x.shrink()
                self.assertEqual(x._pool.size, 1)
                self.assertEqual(x._pool._semaphore.counter, 1)

                x._pool = [4, 5, 6]
                self.assertEqual(x.num_processes, 3)