Exemplo n.º 1
0
 def testIncrementToVeryHighValueThenSetToLowValueThenIncrement(self):
     """
     Create a queue of width 10 and then set its width to 1000 then set
     it to 100, then to 500.  The number of pending stops will be 500.
     """
     dq = ResizableDispatchQueue(None, 10)
     dq.width = 1000
     dq.width = 100
     dq.width = 500
     self.assertEqual(dq.pendingStops, 500)
     return dq.stop()
Exemplo n.º 2
0
 def testNarrowWiden(self):
     """
     Create a queue of width 10. Narrowing to 7 means there will be 3
     pending stops, then widening to 8 will decrease the number of
     pending stops to 2.
     """
     dq = ResizableDispatchQueue(None, 10)
     dq.width = 7
     self.assertEqual(dq.pendingStops, 3)
     dq.width = 8
     self.assertEqual(dq.pendingStops, 2)
     return dq.stop()
Exemplo n.º 3
0
 def testJustOneWithZeroInitialWidth(self):
     # Same as testJustOne (above), except we initialize with zero width
     # and start the dispatcher by explicitly setting its width.
     dq = ResizableDispatchQueue(self.slow)
     map(dq.put, range(3))
     self.assertEqual(0, dq.width)
     dq.width = 1
     return self._stopAndTest(0.0001, dq, [1, 2])
Exemplo n.º 4
0
 def testSetImmediatelyToZero(self):
     """
     Create a queue of width 10 and then set its width to 0.
     The number of pending stops will be 10.
     """
     dq = ResizableDispatchQueue(None, 10)
     dq.width = 0
     self.assertEqual(dq.pendingStops, 10)
     return dq.stop()
Exemplo n.º 5
0
 def testNarrow(self):
     """
     Create a queue of width 5 and narrow it to width 3. There should
     then be 2 pending stops.
     """
     dq = ResizableDispatchQueue(None, 5)
     dq.width = 3
     self.assertEqual(2, dq.pendingStops)
     return dq.stop()
Exemplo n.º 6
0
 def testSetWidthToZeroAfterInitiallyNonZeroThenStop(self):
     """
     Make sure that a queue whose width is initially non-zero and which
     is then set to zero width returns all the added jobs when stopped.
     """
     dq = ResizableDispatchQueue(None, 3)
     dq.width = 0
     dq.put('aaa', 5)
     dq.put('bbb', 10)
     remaining = yield dq.stop()
     self.assertEqual(['aaa', 'bbb'], [job.jobarg for job in remaining])
Exemplo n.º 7
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()