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())
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()
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)
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()
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)