Ticket #5981: 5981v3.patch

File 5981v3.patch, 2.2 KB (added by Stephen Solis, 8 years ago)

Addressed more issues from review and added news file

  • twisted/test/test_threadpool.py

     
    473473
    474474    def test_workerStateTransition(self):
    475475        """
    476         As the worker receives and completes work it should transition between
    477         the working/waiting states.
     476        As the worker receives and completes work, it transitions between
     477        the working and waiting states.
    478478        """
    479479        pool = threadpool.ThreadPool(0,1)
    480480        pool.start()
     
    511511
    512512    def test_workerState(self):
    513513        """
    514         Upon entering a _workerState block the threads unique identifier
    515         should be added to a stateList, and removed upon exiting the block.
     514        Upon entering a _workerState block, the threads unique identifier is
     515        added to a stateList and is removed upon exiting the block.
    516516        """
    517517        pool = threadpool.ThreadPool()
    518518        workerThread = object()
     
    521521            self.assertIn(workerThread, stateList)
    522522        self.assertNotIn(workerThread, stateList)
    523523
    524         # raise an exception instead of running out to test exception state
     524
     525    def test_workerStateExceptionHandling(self):
     526        """
     527        The _workerState block does not consume L{Exception}s or change the
     528        L{Exception} that gets raised.
     529        """
     530        pool = threadpool.ThreadPool()
     531        workerThread = object()
     532        stateList = []
    525533        try:
    526534            with pool._workerState(stateList, workerThread):
    527535                self.assertIn(workerThread, stateList)
    528                 raise Exception()
     536                1/0
     537        except ZeroDivisionError:
     538            pass
    529539        except:
    530             pass
     540            self.fail("_workerState shouldn't change raised exceptions")
    531541        else:
    532             self.fail("_workerState shouldn't be consuming exceptions")
     542            self.fail("_workerState shouldn't consume exceptions")
    533543        self.assertNotIn(workerThread, stateList)
    534544
    535545
    536 
    537546class RaceConditionTestCase(unittest.SynchronousTestCase):
    538547
    539548    def getTimeout(self):