示例#1
0
    def testPoolShrink(self):
        Pyro4.config.THREADPOOL_MINTHREADS = MAX_POOL_SIZE
        tp = ThreadPool()
        tp.workerFactory = WorkerFactory(tp, "workername")
        tp.fill()
        self.assertFalse(tp.poolCritical())
        tp.updateWorking(MAX_POOL_SIZE)
        self.assertTrue(tp.poolCritical())
        Pyro4.config.THREADPOOL_MINTHREADS = MIN_POOL_SIZE
        self.assertEqual(MAX_POOL_SIZE, len(tp))
        self.assertTrue(tp.poolCritical())
        shrunk = tp.shrink()
        self.assertEqual(0, shrunk)
        shrunk = tp.updateWorking(-MAX_POOL_SIZE)
        self.assertFalse(tp.poolCritical())
        self.assertEqual(0, shrunk)  # shouldn't shrink because of the idle timeout
        self.assertEqual(MAX_POOL_SIZE, len(tp))

        # wait until the idle timeout has passed, and try to shrink again
        time.sleep(IDLE_TIMEOUT + 0.2)
        shrunk = tp.updateWorking(0)
        self.assertEqual(MAX_POOL_SIZE - MIN_POOL_SIZE, shrunk)
        # for now we need to actually remove the idle threads ourselves
        for worker in list(tp.pool)[:shrunk]:
            worker.continuerunning = False
            worker.join()
        # the worker, when it exits, must remove itself from the thread pool
        self.assertEqual(MIN_POOL_SIZE, len(tp))
        for worker in tp.pool.copy():
            worker.continuerunning = False
            worker.join()
示例#2
0
 def testPoolCreation(self):
     tp = ThreadPool()
     tp.workerFactory = WorkerFactory(tp, "workername")
     self.assertEqual(0, len(tp))
     tp.fill()
     self.assertEqual(MIN_POOL_SIZE, len(tp))
     for worker in tp.pool.copy():
         worker.continuerunning = False
         worker.join()
示例#3
0
 def testPoolGrowth(self):
     self.skipTest("pool size is fixed until thread pool scaling bug has been resolved")  # XXX
     tp = ThreadPool()
     tp.workerFactory = WorkerFactory(tp, "workername")
     tp.fill()
     self.assertEqual(MIN_POOL_SIZE, len(tp))
     self.assertFalse(tp.poolCritical())
     spawned = tp.growIfNeeded()
     self.assertFalse(spawned)
     tp.updateWorking(5)
     self.assertTrue(tp.poolCritical())
     spawned = tp.growIfNeeded()
     self.assertTrue(spawned)
     self.assertEqual(6, len(tp))
     tp.updateWorking(5)  # total number of 'working' threads now sits at 10
     for _ in range(MAX_POOL_SIZE * 2):
         tp.growIfNeeded()
     self.assertEqual(MAX_POOL_SIZE, len(tp))  # shouldn't grow beyond max size
     for worker in tp.pool.copy():
         worker.continuerunning = False
         worker.join()