Пример #1
0
 def test_not_sent_until_permitted(self):
     i = DeferredIOWorker(IOWorker())
     i.set_receive_handler(self.call_later)
     i.block()
     i.send("foo")
     self.assertFalse(i._io_worker._ready_to_send)
     self.assertFalse(i._send_queue.empty())
     i.unblock()
     self.assertTrue(i._send_queue.empty())
     i._io_worker._consume_send_buf(3)
     self.assertFalse(i._io_worker._ready_to_send)
Пример #2
0
 def test_not_sent_until_permitted(self):
   i = DeferredIOWorker(IOWorker())
   i.set_receive_handler(self.call_later)
   i.block()
   i.send("foo")
   self.assertFalse(i._io_worker._ready_to_send)
   self.assertFalse(i._send_queue.empty())
   i.unblock()
   self.assertTrue(i._send_queue.empty())
   i._io_worker._consume_send_buf(3)
   self.assertFalse(i._io_worker._ready_to_send)
Пример #3
0
 def test_receive_consume(self):
   i = DeferredIOWorker(IOWorker())
   i.set_receive_handler(self.call_later)
   self.data = None
   def consume(worker):
     self.data = worker.peek_receive_buf()
     worker.consume_receive_buf(len(self.data))
   i.set_receive_handler(consume)
   i.block()
   i._io_worker._push_receive_data("bar")
   self.assertEqual(self.data, None)
   i.unblock()
   self.assertEqual(self.data, "bar")
   # data has been consumed
   i._io_worker._push_receive_data("hepp")
   self.assertEqual(self.data, "hepp")
Пример #4
0
 def test_not_received_until_permitted(self):
   i = DeferredIOWorker(IOWorker())
   i.set_receive_handler(self.call_later)
   i.block()
   self.data = None
   def d(worker):
     self.data = worker.peek_receive_buf()
   i.set_receive_handler(d)
   i._io_worker._push_receive_data("bar")
   self.assertEqual(self.data, None)
   i.unblock()
   self.assertEqual(self.data, "bar")
   # Now if unblocked, should go through immediately
   # Note: d does not consume the data
   i._io_worker._push_receive_data("hepp")
   self.assertEqual(self.data, "barhepp")
Пример #5
0
    def test_receive_consume(self):
        i = DeferredIOWorker(IOWorker())
        i.set_receive_handler(self.call_later)
        self.data = None

        def consume(worker):
            self.data = worker.peek_receive_buf()
            worker.consume_receive_buf(len(self.data))

        i.set_receive_handler(consume)
        i.block()
        i._io_worker._push_receive_data("bar")
        self.assertEqual(self.data, None)
        i.unblock()
        self.assertEqual(self.data, "bar")
        # data has been consumed
        i._io_worker._push_receive_data("hepp")
        self.assertEqual(self.data, "hepp")
Пример #6
0
    def test_not_received_until_permitted(self):
        i = DeferredIOWorker(IOWorker())
        i.set_receive_handler(self.call_later)
        i.block()
        self.data = None

        def d(worker):
            self.data = worker.peek_receive_buf()

        i.set_receive_handler(d)
        i._io_worker._push_receive_data("bar")
        self.assertEqual(self.data, None)
        i.unblock()
        self.assertEqual(self.data, "bar")
        # Now if unblocked, should go through immediately
        # Note: d does not consume the data
        i._io_worker._push_receive_data("hepp")
        self.assertEqual(self.data, "barhepp")