Exemplo n.º 1
0
 def testSimplePending(self):
     """
     Putting 3 jobs onto a queue with zero width should result in a
     number of pending jobs of 3.
     """
     dq = ResizableDispatchQueue(None)
     map(dq.put, range(3))
     self.assertEqual((0, 3), dq.size())
Exemplo n.º 2
0
    def testClearQueueCancelPending(self):
        """
        When the queue is cleared with cancelPending=True, the pending jobs
        should fail and receive a job whose state is CANCELLED.
        """
        def ok(result):
            self.fail('Unexpected success!')

        def checkCancel(failure):
            self.assertEqual(failure.value.state, Job.CANCELLED)

        dq = ResizableDispatchQueue(None, 2)
        dq.put(0).addCallbacks(ok, checkCancel)
        dq.put(1).addCallbacks(ok, checkCancel)
        self.assertEqual((0, 2), dq.size())
        dq.clearQueue(cancelPending=True)
        self.assertEqual((0, 0), dq.size())
        yield dq.stop()
Exemplo n.º 3
0
 def testSetWidthToZeroAfterInitiallyNonZero(self):
     """
     Make sure that a queue whose width is initially non-zero and which
     is then set to zero width does not then begin to process any added
     jobs.
     """
     dq = ResizableDispatchQueue(None, 3)
     dq.width = 0
     dq.put('aaa')
     dq.put('bbb')
     self.assertEqual((0, 2), dq.size())
     return dq.stop()
Exemplo n.º 4
0
 def testUnstarted(self):
     """
     Check basic facts about a fresh instance of a
     ResizableDispatchQueue.
     """
     dq = ResizableDispatchQueue(None)
     self.assertEqual(dq.pending(), [])
     self.assertEqual(dq.underway(), set())
     self.assertFalse(dq.stopped)
     self.assertFalse(dq.paused)
     self.assertEqual((0, 0), dq.size())
     return dq.stop()
Exemplo n.º 5
0
 def testClearQueue(self):
     dq = ResizableDispatchQueue(None)
     map(dq.put, range(3))
     self.assertEqual((0, 3), dq.size())
     dq.clearQueue(cancelPending=False)
     self.assertEqual((0, 0), dq.size())