def _test_pinging(self): ctx = zmq.Context() locker = threading.RLock() socket = ctx.socket(zmq.REQ) socket.connect(_ENDPOINT) ponger = Ponger(ctx) failures = [0] def failed(): failures[0] += 1 ponger.start() time.sleep(0.2) pinger = Pinger('me', socket, locker, failed, duration=0.1) pinger.start() time.sleep(0.2) ponger.join() ctx.destroy(0) pinger.stop() # let's see how many ping we did self.assertEqual(ponger.count, 5)
def __init__(self, endpoint, identity, target, timeout=1.): self.identity = identity self.ctx = zmq.Context() self.timeout = timeout * 1000 self.master = self.ctx.socket(zmq.REQ) self.master.connect(endpoint) self.work = self.ctx.socket(zmq.REP) self.work.bind(identity) self.registered = self.running = False # setting a poller self.poller = zmq.Poller() self.poller.register(self.work, zmq.POLLIN) self.locker = threading.RLock() self.pinger = Pinger(self.identity, self.master, self.locker, self.failed) self.target = target
def test_too_many_failures(self): ctx = zmq.Context() locker = threading.RLock() socket = ctx.socket(zmq.REQ) socket.connect(_ENDPOINT) failures = [0] def failed(): failures[0] += 1 pinger = Pinger('me', socket, locker, failed, duration=0.1) pinger.start() time.sleep(1.) # pinging 10 times nowwhere will make the pinger quit #pinger.join() ctx.destroy(0) self.assertTrue(len(failures), 10) self.assertTrue(pinger.unresponsive)