def connectToMissing(self, currentTime): """ Try to connect to the missing node within the time specified by `reconnectToMissingIn` :param currentTime: the current time """ missing = self.reconcileNodeReg() if missing: logger.debug( "{} found the following missing connections: {}".format( self, ", ".join(missing))) if self.connectNicelyUntil is None: self.connectNicelyUntil = \ currentTime + self.reconnectToMissingIn if currentTime <= self.connectNicelyUntil: names = list(self.registry.keys()) names.append(self.name) nices = set(distributedConnectionMap(names)[self.name]) for name in nices: logger.debug( "{} being nice and waiting for {} to join".format( self, name)) missing = missing.difference(nices) for name in missing: self.connect(name)
def connectToMissing(self, currentTime): """ Try to connect to the missing node within the time specified by `reconnectToMissingIn` :param currentTime: the current time """ missing = self.reconcileNodeReg() if missing: logger.debug("{} found the following missing connections: {}". format(self, ", ".join(missing))) if self.connectNicelyUntil is None: self.connectNicelyUntil = \ currentTime + self.reconnectToMissingIn if currentTime <= self.connectNicelyUntil: names = list(self.nodeReg.keys()) names.append(self.name) nices = set(distributedConnectionMap(names)[self.name]) for name in nices: logger.debug("{} being nice and waiting for {} to join". format(self, name)) missing = missing.difference(nices) for name in missing: self.connect(name)
def test_distributedConnectionMapIsDeterministic(): """ While this doesn't prove determinism, it gives us confidence. For 20 iterations, it generates 24 random names, and 10 conmaps for those names, and compares that the conmaps generated for the same names are the same. """ for _ in range(20): rands = [randomString() for _ in range(24)] conmaps = [distributedConnectionMap(rands) for _ in range(10)] for conmap1, conmap2 in combinations(conmaps, 2): assert conmap1 == conmap2
def test_distributedConnectionMap(): for nodeCount in range(2, 25): print("testing for node count: {}".format(nodeCount)) names = genNodeNames(nodeCount) conmap = distributedConnectionMap(names) total_combinations = len(list(combinations(names, 2))) total_combinations_in_map = sum(len(x) for x in conmap.values()) assert total_combinations_in_map == total_combinations maxPer = math.ceil(total_combinations / nodeCount) minPer = math.floor(total_combinations / nodeCount) for x in conmap.values(): assert len(x) <= maxPer assert len(x) >= minPer
def connectToMissing(self, currentTime): missing = self.reconcileNodeReg() if missing: logger.debug("{} found the following missing connections: {}". format(self, ", ".join(missing))) if self.connectNicelyUntil is None: self.connectNicelyUntil = currentTime + 3 if currentTime <= self.connectNicelyUntil: names = list(self.nodeReg.keys()) names.append(self.name) nices = set(distributedConnectionMap(names)[self.name]) for name in nices: logger.debug("{} being nice and waiting for {} to join". format(self, name)) missing = missing.difference(nices) for name in missing: self.connect(name)