Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
 def bootstrap(self, forced: bool = None):
     """
     Connect to all nodes in the node registry.
     """
     logging.info("{} is bootstrapping, forced is {}".format(self, forced), extra={"cli": False})
     missing = self.reconcileNodeReg()
     if missing:
         logger.debug("{} found the following missing connections: {}".format(self, ", ".join(missing)))
         if not forced:
             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)
     self.bootstrapped = True