예제 #1
0
    def __init__(self, *args, **kwargs):
        self.nodeMsgRouter.routes[TestMsg] = self.eatTestMsg
        self.nodeIbStasher = Stasher(self.nodeInBox,
                                     "nodeInBoxStasher~" + self.name)
        self.clientIbStasher = Stasher(self.clientInBox,
                                       "clientInBoxStasher~" + self.name)
        self.actionQueueStasher = Stasher(self.actionQueue,
                                          "actionQueueStasher~" + self.name)

        # alter whitelist to allow TestMsg type through without sig
        self.authnWhitelist = self.authnWhitelist + (TestMsg, )

        # Nodes that wont be blacklisted by this node if the suspicion code
        # is among the set of suspicion codes mapped to its name. If the set of
        # suspicion codes is empty then the node would not be blacklisted for
        #  any suspicion code
        self.whitelistedNodes = {}  # type: Dict[str, Set[int]]

        # Clients that wont be blacklisted by this node if the suspicion code
        # is among the set of suspicion codes mapped to its name. If the set of
        # suspicion codes is empty then the client would not be blacklisted for
        #  suspicion code
        self.whitelistedClients = {}  # type: Dict[str, Set[int]]

        # Reinitialize the monitor
        d, l, o = self.monitor.Delta, self.monitor.Lambda, self.monitor.Omega
        notifierEventTriggeringConfig = self.monitor.notifierEventTriggeringConfig
        self.instances = Instances()

        self.nodeInfo = {'data': {}}

        pluginPaths = kwargs.get('pluginPaths', [])
        self.monitor = TestMonitor(
            self.name,
            d,
            l,
            o,
            self.instances,
            MockedNodeStack(),
            MockedBlacklister(),
            nodeInfo=self.nodeInfo,
            notifierEventTriggeringConfig=notifierEventTriggeringConfig,
            pluginPaths=pluginPaths)
        for i in self.replicas.keys():
            self.monitor.addInstance(i)
        self.replicas._monitor = self.monitor
        self.replicas.register_monitor_handler()
예제 #2
0
def test_delay_rules_dont_touch_other_delays():
    s = Stasher(deque())
    s.delay(delay_threes)

    with delay_rules(s, delay_twos):
        assert delay_threes in s.delayRules

    assert delay_threes in s.delayRules
예제 #3
0
def test_delay_rules_can_use_multiple_delayers():
    s = Stasher(deque())

    with delay_rules(s, delay_twos, delay_threes):
        assert delay_twos in s.delayRules
        assert delay_threes in s.delayRules

    assert delay_twos not in s.delayRules
    assert delay_threes not in s.delayRules
예제 #4
0
def test_unstash_appends_to_right():
    q = deque([1, 2, 3])
    s = Stasher(q, "my-stasher")

    s.delay(delay_all)
    s.process()
    assert len(q) == 0

    s.force_unstash()
    assert q == deque([1, 2, 3])
예제 #5
0
def test_delay_rules_can_use_generator_expressions():
    stashers = [Stasher(deque(), name="{}".format(i)) for i in range(3)]

    with delay_rules((s for s in stashers if s.name != "1"), delay_twos):
        assert delay_twos in stashers[0].delayRules
        assert delay_twos not in stashers[1].delayRules
        assert delay_twos in stashers[2].delayRules

    assert delay_twos not in stashers[0].delayRules
    assert delay_twos not in stashers[1].delayRules
    assert delay_twos not in stashers[2].delayRules
예제 #6
0
def test_delay_rules_return_delayed_items_to_list_on_exit():
    q = deque([1, 2, 3])
    s = Stasher(q)
    s.delay(delay_threes)

    with delay_rules(s, delay_twos):
        s.process()
        assert 1 in q
        assert 2 not in q
        assert 3 not in q

    assert 1 in q
    assert 2 in q
    assert 3 not in q
예제 #7
0
def test_delay():
    x = deque()
    s = Stasher(x, "my-stasher")
    x.append(1)
    x.append(2)
    x.append(3)

    def delayTwos(item):
        if item == 2:
            return 2

    s.delay(delayTwos)

    s.process()
    r1 = x.popleft()
    assert r1 == 1

    r2 = x.popleft()
    assert r2 == 3

    with pytest.raises(IndexError):
        x.popleft()

    time.sleep(1)
    s.process()

    with pytest.raises(IndexError):
        x.popleft()

    time.sleep(1)
    s.process()

    r3 = x.popleft()
    assert r3 == 2

    x.append(2)
    s.resetDelays()
    s.process()
    assert 2 == x.popleft()
예제 #8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     # Each TestReplica gets it's own outbox stasher, all of which TestNode
     # processes in its overridden serviceReplicaOutBox
     self.outBoxTestStasher = \
         Stasher(self.outBox, "replicaOutBoxTestStasher~" + self.name)
예제 #9
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.actionQueueStasher = Stasher(
         self.actionQueue, "actionQueueStasher~elector~" + self.name)
예제 #10
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.stasher = Stasher(self.rxMsgs, "TestStack~" + self.name)

        self.delay = self.stasher.delay