def test_lossy(self): bromine.CONFIG['n'] = 3 # can't do it with N being even score_board = bromine.Scoreboard() systems = bromine.Systems() payload = data(30) score_board.push_data(payload) iterations = 0 while len(systems.data) < 30: iterations += 1 #self.assertTrue(iterations < 100) address = score_board.transmit() mids = address_to_mids(address) if len(mids) == 1 and random.random() < 0.9: pass # drop # random number generation is heavily tilted towards # small systems... dropping all of them is difficult else: # keep complex systems and some singletons, hope to reconstruct # all messages systems.add(address) score_board.retire(systems.last_seen_remote_mid) self.assertEqual(b''.join(systems.data), payload)
def __init__(self, channel_id): self.channel_id = channel_id # data going out self.score_board = bromine.Scoreboard() self.last_ack = bromine.INVALID_MID # data coming in self.systems = bromine.Systems()
def test_ack(self): score_board = bromine.Scoreboard() systems = bromine.Systems() score_board.last_seen_remote_mid = 42 ack = score_board.transmit() self.assertTrue(bromine.valid_dns_name(ack)) if score_board.mid == 1: systems.add(ack) self.assertEqual(systems.acks, [(42, 0)])
def test_data(self): score_board = bromine.Scoreboard() systems = bromine.Systems() payload = data(1) score_board.push_data(payload) loaded = score_board.transmit() self.assertTrue(bromine.valid_dns_name(loaded)) if score_board.mid == 1: systems.add(loaded) self.assertEqual(len(systems.data), 1) self.assertEqual(systems.data[0], payload)
def __init__(self): if TESTING: self.resolver = client.Resolver(servers=[('127.0.0.1', 5553)]) else: # self.resolver = client.Resolver('/etc/resolv.conf') self.resolver = client.Resolver(servers=[('8.8.8.8', 53)]) # data going out self.score_board = bromine.Scoreboard() self.last_ack = bromine.INVALID_MID # data coming in self.systems = bromine.Systems() # keep track of callbacks self.requested = 0 # looping call not withstanding LoopingCall(self.pump).start(SLOW)
def test_variety(self): score_board = bromine.Scoreboard() SOME = 5 for _ in range(SOME): score_board.push_data(data(1)) for i in range(SOME): address = score_board.transmit() mids = address_to_mids(address) if len(mids) > 1: # systems get complex very soon break else: self.assertFalse("should have break'd") addresses = set() for i in range(10 * SOME): address = score_board.transmit() self.assertFalse(address in addresses) addresses.add(address)
def __init__(self): self.emit = bromine.Scoreboard() self.recv = bromine.Systems() self.data = []