def setUp(self): """ Create a dummy supvisors and a ZMQ context. """ from supvisors.supvisorszmq import create_zmq_context # the dummy Supvisors is used for addresses and ports self.supvisors = DummySupvisors() # create the ZeroMQ context self.zmq_context = create_zmq_context()
def test_create_context(self): """ Create a dummy supvisors and a ZMQ context. """ from supvisors.supvisorszmq import create_zmq_context # create and check context zmq_context = create_zmq_context() self.assertIsInstance(zmq_context, zmq.Context) self.assertFalse(zmq_context.closed) self.assertEqual(0, zmq_context.getsockopt(zmq.LINGER)) # destroy the context zmq_context.destroy() self.assertTrue(zmq_context.closed)
def setUp(self): """ Create a dummy supvisors, ZMQ context and sockets. """ from supvisors.supvisorszmq import create_zmq_context, RequestPusher, RequestPuller # the dummy Supvisors is used for addresses and ports self.supvisors = DummySupvisors() # create the ZeroMQ context self.zmq_context = create_zmq_context() # create pusher and puller self.pusher = RequestPusher(self.zmq_context, self.supvisors) self.puller = RequestPuller(self.zmq_context, self.supvisors) # socket configuration is meant to be blocking # however, a failure would block the unit test, so a timeout is set for reception self.puller.socket.setsockopt(zmq.RCVTIMEO, 1000)
def setUp(self): """ Create a dummy supvisors, ZMQ context and sockets. """ from supvisors.supvisorszmq import create_zmq_context, InternalEventPublisher, InternalEventSubscriber # the dummy Supvisors is used for addresses and ports self.supvisors = DummySupvisors() # create the ZeroMQ context self.zmq_context = create_zmq_context() # create publisher and subscriber self.publisher = InternalEventPublisher(self.zmq_context, self.supvisors) self.subscriber = InternalEventSubscriber(self.zmq_context, self.supvisors) # socket configuration is meant to be blocking # however, a failure would block the unit test, so a timeout is set for reception self.subscriber.socket.setsockopt(zmq.RCVTIMEO, 1000) # publisher does not wait for subscriber clients to work, so give some time for connections time.sleep(1)
def setUp(self): """ Create a dummy supvisors and a ZMQ context. """ from supvisors.supvisorszmq import create_zmq_context, EventPublisher, EventSubscriber # the dummy Supvisors is used for addresses and ports self.supvisors = DummySupvisors() # create the ZeroMQ context self.zmq_context = create_zmq_context() # create publisher and subscriber self.publisher = EventPublisher(self.zmq_context, self.supvisors) self.subscriber = EventSubscriber(self.zmq_context, self.supvisors.options.event_port, self.supvisors.logger) # WARN: this subscriber does not include a subscription # when using a subscription, use a time sleep to give time to PyZMQ to handle it # WARN: socket configuration is meant to be blocking # however, a failure would block the unit test, so a timeout is set for reception self.subscriber.socket.setsockopt(zmq.RCVTIMEO, 1000) # create test payloads self.supvisors_payload = Payload({ 'state': 'running', 'version': '1.0' }) self.address_payload = Payload({ 'state': 'silent', 'name': 'cliche01', 'date': 1234 }) self.application_payload = Payload({ 'state': 'starting', 'name': 'supvisors' }) self.process_payload = Payload({ 'state': 'running', 'process_name': 'plugin', 'application_name': 'supvisors', 'date': 1230 })
self.logger.info('got ApplicationStatus message: {}'.format(data)) if __name__ == '__main__': # get arguments import argparse, time parser = argparse.ArgumentParser( description='Start a subscriber to Supvisors events.') parser.add_argument('-p', '--port', type=int, default=60002, help="the event port of Supvisors") parser.add_argument('-s', '--sleep', type=int, metavar='SEC', default=10, help="the duration of the subscription") args = parser.parse_args() # create test subscriber loop = SupvisorsEventInterface(create_zmq_context(), args.port, create_logger()) loop.subscriber.subscribe_all() # start thread and sleep for a while loop.start() time.sleep(args.sleep) # stop thread and halt loop.stop() loop.join()