def test_getServers(self): from asyncore import socket_map class DummySocketServer: def __init__(self, port): self.port = port class AnotherSocketServer(DummySocketServer): pass class NotAServer: pass am = self._makeOne() _old_socket_map = socket_map.copy() socket_map.clear() socket_map['foo'] = DummySocketServer(45) socket_map['bar'] = AnotherSocketServer(57) socket_map['qux'] = NotAServer() try: pairs = am.getServers() finally: socket_map.clear() socket_map.update(_old_socket_map) self.assertEqual(len(pairs), 2) self.assertTrue((str(DummySocketServer), 'Port: 45') in pairs) self.assertTrue((str(AnotherSocketServer), 'Port: 57') in pairs)
def _make_http_servers(self, sconfigs): options = DummyOptions() options.server_configs = sconfigs options.rpcinterface_factories = [('dummy',DummyRPCInterfaceFactory,{})] supervisord = DummySupervisor() from supervisor.http import make_http_servers servers = make_http_servers(options, supervisord) try: for config, s in servers: s.close() socketfile = config.get('file') if socketfile is not None: os.unlink(socketfile) finally: from asyncore import socket_map socket_map.clear() return servers