MCPcopy Index your code
hub / github.com/python/cpython / failing_queue_test

Method failing_queue_test

Lib/test/test_queue.py:735–814  ·  view source on GitHub ↗
(self, q)

Source from the content-addressed store, hash-verified

733 super().setUp()
734
735 def failing_queue_test(self, q):
736 if q.qsize():
737 raise RuntimeError("Call this function with an empty queue")
738 for i in range(QUEUE_SIZE-1):
739 q.put(i)
740 # Test a failing non-blocking put.
741 q.fail_next_put = True
742 try:
743 q.put("oops", block=0)
744 self.fail("The queue didn't fail when it should have")
745 except FailingQueueException:
746 pass
747 q.fail_next_put = True
748 try:
749 q.put("oops", timeout=0.1)
750 self.fail("The queue didn't fail when it should have")
751 except FailingQueueException:
752 pass
753 q.put("last")
754 self.assertTrue(qfull(q), "Queue should be full")
755 # Test a failing blocking put
756 q.fail_next_put = True
757 try:
758 self.do_blocking_test(q.put, ("full",), q.get, ())
759 self.fail("The queue didn't fail when it should have")
760 except FailingQueueException:
761 pass
762 # Check the Queue isn't damaged.
763 # put failed, but get succeeded - re-add
764 q.put("last")
765 # Test a failing timeout put
766 q.fail_next_put = True
767 try:
768 self.do_exceptional_blocking_test(q.put, ("full", True, 10), q.get, (),
769 FailingQueueException)
770 self.fail("The queue didn't fail when it should have")
771 except FailingQueueException:
772 pass
773 # Check the Queue isn't damaged.
774 # put failed, but get succeeded - re-add
775 q.put("last")
776 self.assertTrue(qfull(q), "Queue should be full")
777 q.get()
778 self.assertTrue(not qfull(q), "Queue should not be full")
779 q.put("last")
780 self.assertTrue(qfull(q), "Queue should be full")
781 # Test a blocking put
782 self.do_blocking_test(q.put, ("full",), q.get, ())
783 # Empty it
784 for i in range(QUEUE_SIZE):
785 q.get()
786 self.assertTrue(not q.qsize(), "Queue should be empty")
787 q.put("first")
788 q.fail_next_get = True
789 try:
790 q.get()
791 self.fail("The queue didn't fail when it should have")
792 except FailingQueueException:

Callers 1

test_failing_queueMethod · 0.95

Calls 8

qfullFunction · 0.85
assertTrueMethod · 0.80
do_blocking_testMethod · 0.80
qsizeMethod · 0.45
putMethod · 0.45
failMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected