'test router-router MQ devices'

def test_router_router(self):

    dev = devices.ThreadMonitoredQueue(zmq.ROUTER, zmq.ROUTER, zmq.PUB, 'in', 'out')
    self.device = dev
    dev.setsockopt_in(zmq.LINGER, 0)
    dev.setsockopt_out(zmq.LINGER, 0)
    dev.setsockopt_mon(zmq.LINGER, 0)
    binder = self.context.socket(zmq.DEALER)
    porta = binder.bind_to_random_port('tcp://127.0.0.1')
    portb = binder.bind_to_random_port('tcp://127.0.0.1')
    binder.close()
    time.sleep(0.1)
    a = self.context.socket(zmq.DEALER)
    a.identity = 'a'
    b = self.context.socket(zmq.DEALER)
    b.identity = 'b'
    self.sockets.extend([a, b])
    a.connect(('tcp://127.0.0.1:%i' % porta))
    dev.bind_in(('tcp://127.0.0.1:%i' % porta))
    b.connect(('tcp://127.0.0.1:%i' % portb))
    dev.bind_out(('tcp://127.0.0.1:%i' % portb))
    dev.start()
    time.sleep(0.2)
    if (zmq.zmq_version_info() >= (3, 1, 0)):
        ping_msg = ['ping', 'pong']
        for s in (a, b):
            s.send_multipart(ping_msg)
            try:
                s.recv(zmq.NOBLOCK)
            except zmq.ZMQError:
                pass
    msg = ['hello', 'there']
    a.send_multipart((['b'] + msg))
    bmsg = self.recv_multipart(b)
    self.assertEqual(bmsg, (['a'] + msg))
    b.send_multipart(bmsg)
    amsg = self.recv_multipart(a)
    self.assertEqual(amsg, (['b'] + msg))
    self.teardown_device()
