def testFactory(factory, data, clients=100): '''Tests the given factory with the given data packets.''' from base import Server port = process.randomPort() print 'Starting', factory, 'with', factory.protocol, 'on port', port server = Server(('', port), factory) server.serve() jobs = [] for c in range(0, clients): jobs.append(gevent.spawn(testSendData, data, port)) gevent.joinall(jobs, timeout=15) vals = [(1 if job.value else 0) for job in jobs] print sum(vals), '/', len(vals), 'succeeded' return sum(vals) * 1.0 / len(vals)
def _parse_arguments(self, cmd, port=None, clientid=None, **kwargs): '''Parse all the arguments and add them to the command.''' if isinstance(cmd, str): cmd = cmd.split(' ') if '-p' not in cmd and '--port' not in cmd: if port is None: port = process.randomPort() cmd.append('-p') cmd.append(str(port)) self.port = int(cmd[cmd.index('-p') + 1]) if '-i' not in cmd and '--client-id' not in cmd: if clientid is None: clientid = 'server' cmd.append('-i') cmd.append(clientid) self.clientid = cmd[cmd.index('-i') + 1] self.cmd = ' '.join(cmd)