'Test monitoring interface for sockets.'

@require_zmq_4
def test_monitor(self):

    s_rep = self.context.socket(zmq.REP)
    s_req = self.context.socket(zmq.REQ)
    self.sockets.extend([s_rep, s_req])
    s_req.bind('tcp://127.0.0.1:6666')
    s_rep.monitor('inproc://monitor.rep', zmq.EVENT_ALL)
    s_event = self.context.socket(zmq.PAIR)
    self.sockets.append(s_event)
    s_event.connect('inproc://monitor.rep')
    s_event.linger = 0
    s_rep.connect('tcp://127.0.0.1:6666')
    m = recv_monitor_message(s_event)
    if (m['event'] == zmq.EVENT_CONNECT_DELAYED):
        self.assertEqual(m['endpoint'], 'tcp://127.0.0.1:6666')
        m = recv_monitor_message(s_event)
    self.assertEqual(m['event'], zmq.EVENT_CONNECTED)
    self.assertEqual(m['endpoint'], 'tcp://127.0.0.1:6666')
    s_rep.disable_monitor()
    m = recv_monitor_message(s_event)
    self.assertEqual(m['event'], zmq.EVENT_MONITOR_STOPPED)
