Пример #1
0
    def escalate_failure(self, reason: Exception, obj: object) -> None:
        if self.__restart_statistics is None:
            self.__restart_statistics = RestartStatistics(0, None)

        failure = Failure(self.my_self, reason, self.__restart_statistics)
        self.my_self.send_system_message(SuspendMailbox())

        if self.parent is None:
            self.__handle_root_failure(failure)
        else:
            self.parent.send_system_message(failure)
def supervisor_data():
    supervisor = TestSupervisor()
    mailbox = Mailbox(None, None, None, None)
    local_process = LocalProcess(mailbox)
    pid_child = PID(address='address', id='id', ref=local_process)
    restart_statistic = RestartStatistics(5, datetime(2017, 2, 15))

    return {
        'supervisor': supervisor,
        'mailbox': mailbox,
        'local_process': local_process,
        'pid_child': pid_child,
        'restart_statistic': restart_statistic
    }
def test_is_within_duration():
    rs = RestartStatistics(10, datetime.datetime(2017, 2, 14, 0, 0, 0))
    assert rs.is_within_duration(timedelta(days=1, seconds=1)) is False
def test_is_not_within_duration():
    rs = RestartStatistics(10, datetime.datetime.now())
    assert rs.is_within_duration(timedelta(seconds=1)) is True
def test_number_of_failures():
    rs = RestartStatistics(10, datetime.datetime(2017, 2, 14, 0, 0, 0))
    assert rs.number_of_failures(timedelta(days=1, seconds=1)) == 0
def test_number_of_failures_greater_then_zero():
    rs = RestartStatistics(10, datetime.datetime.now())
    assert rs.number_of_failures(timedelta(seconds=1)) == 10