Ejemplo n.º 1
0
  def test_run_read(self):
    loop = RecocoIOLoop()
    (left, right) = MockSocket.pair()
    worker = loop.create_worker_for_socket(left)

    # callback for ioworker to record receiving
    self.received = None
    def r(worker):
      self.received = worker.peek_receive_buf()
    worker.set_receive_handler(r)

    # 'start' the run (dark generator magic here). Does not actually execute run, but 'yield' a generator
    g = loop.run()
    # g.next() will call it, and get as far as the 'yield select'
    select = g.next()

    # send data on other socket half
    right.send("hallo")

    # now we emulate the return value of the select ([rlist],[wlist], [elist])
    g.send(([worker], [], []))

    # that should result in the socket being red the data being handed
    # to the ioworker, the callback being called. Everybody happy.
    self.assertEquals(self.received, "hallo")
Ejemplo n.º 2
0
 def test_empty_recv(self):
     """ test_empty_recv: Check that empty reads on socket return ""
    Note that this is actually non-sockety behavior and should probably be changed. This
    test documents it as intended for now, though
 """
     (a, b) = MockSocket.pair()
     self.assertEquals(a.recv(), b'')
Ejemplo n.º 3
0
    def test_run_read(self):
        loop = RecocoIOLoop()
        (left, right) = MockSocket.pair()
        worker = loop.new_worker(left)

        # callback for ioworker to record receiving
        self.received = None

        def r(worker):
            self.received = worker.peek()

        worker.rx_handler = r

        # 'start' the run (dark generator magic here).
        # Does not actually execute run, but 'yield' a generator
        g = loop.run()
        # g.next() will call it, and get as far as the 'yield select'
        select = next(g)

        # send data on other socket half
        right.send(b"hallo")

        # now we emulate the return value of the select ([rlist],[wlist], [elist])
        g.send(([worker], [], []))

        # that should result in the socket being red the data being handed
        # to the ioworker, the callback being called. Everybody happy.
        self.assertEqual(self.received, b"hallo")
Ejemplo n.º 4
0
    def test_ready_to_recv(self):
        (a, b) = MockSocket.pair()
        a.send(b"Hallo")
        self.assertFalse(a.ready_to_recv())
        self.assertTrue(b.ready_to_recv())
        self.assertEquals(b.recv(), b"Hallo")
        self.assertFalse(b.ready_to_recv())

        self.assertFalse(a.ready_to_recv())
        b.send(b"Servus")
        self.assertTrue(a.ready_to_recv())
        self.assertEquals(a.recv(), b"Servus")
        self.assertFalse(a.ready_to_recv())
Ejemplo n.º 5
0
  def test_run_close(self):
    loop = RecocoIOLoop()
    (left, right) = MockSocket.pair()
    worker = loop.new_worker(left)

    self.assertFalse(worker in loop._workers,  "Should not add to _workers yet, until we start up the loop")
    self.assertTrue(len(loop._pending_commands) == 1, "Should have added pending create() command")
    worker.close()
    # This causes the worker to be scheduled to be closed -- it also 
    # calls pinger.ping(). However, the Select task won't receive the ping
    # Until after this method has completed! Thus, we only test whether
    # worker has been added to the pending close queue
    self.assertTrue(len(loop._pending_commands) == 2, "Should have added pending close() command")
Ejemplo n.º 6
0
  def test_run_write(self):
    loop = RecocoIOLoop()
    (left, right) = MockSocket.pair()
    worker = loop.new_worker(left)

    worker.send("heppo")
    # 'start' the run (dark generator magic here). Does not actually execute run, but 'yield' a generator
    g = loop.run()
    # g.next() will call it, and get as far as the 'yield select'
    select = g.next()

    # now we emulate the return value of the select ([rlist],[wlist], [elist])
    g.send(([], [worker], []))

    # that should result in the stuff being sent on the socket
    self.assertEqual(right.recv(), "heppo")
Ejemplo n.º 7
0
    def test_on_ready_to_recv(self):
        self.seen_size = -1
        self.called = 0

        def ready(socket, size):
            self.called += 1
            self.seen_size = size

        (a, b) = MockSocket.pair()
        b.set_on_ready_to_recv(ready)
        self.assertEquals(self.called, 0)
        a.send(b"Hallo")
        self.assertEquals(self.called, 1)
        self.assertEquals(self.seen_size, 5)

        # check that it doesn't get called on the other sockets data
        b.send(b"Huhu")
        self.assertEquals(self.called, 1)
Ejemplo n.º 8
0
 def test_basic(self):
     loop = RecocoIOLoop()
     (left, right) = MockSocket.pair()
     loop.new_worker(left)
Ejemplo n.º 9
0
 def test_simple_send(self):
     (a, b) = MockSocket.pair()
     a.send(b"Hallo")
     self.assertEquals(b.recv(), b"Hallo")
     b.send(b"Servus")
     self.assertEquals(a.recv(), b"Servus")
Ejemplo n.º 10
0
 def test_basic(self):
     loop = RecocoIOLoop()
     (left, right) = MockSocket.pair()
     loop.create_worker_for_socket(left)