def test_allforone_handle_failure_restart_directive_cant_restart(supervisor_data):
    pid1 = PID()
    pid1.address = 'address1'
    pid1.id = 'id1'
    pid2 = PID()
    pid2.address = 'address2'
    pid2.id = 'id2'
    children_pids = [pid1, pid2]

    supervisor_data['supervisor'].stop_children = Mock()
    supervisor_data['restart_statistic'].number_of_failures = Mock(return_value=15)
    supervisor_data['supervisor'].children = Mock(return_value=children_pids)
    exc = Exception()

    decider = lambda pid, cause: SupervisorDirective.Restart

    one_for_one = AllForOneStrategy(decider, 10, timedelta(seconds=20))
    one_for_one.request_restart_permission = Mock(return_value=False)

    one_for_one.handle_failure(supervisor_data['supervisor'],
                               supervisor_data['pid_child'],
                               supervisor_data['restart_statistic'],
                               exc)

    supervisor_data['supervisor'].stop_children\
        .assert_called_once_with(*children_pids)
Пример #2
0
async def test_allforone_handle_failure_restart_directive_can_restart(supervisor_data):
    pid1 = PID()
    pid1.address = 'address1'
    pid1.id = 'id1'
    pid2 = PID()
    pid2.address = 'address2'
    pid2.id = 'id2'
    children_pids = [pid1, pid2]

    supervisor_data['local_process'].send_system_message = AsyncMock()
    supervisor_data['supervisor'].restart_children = AsyncMock()
    supervisor_data['supervisor'].children = Mock(return_value=children_pids)
    exc = Exception()

    decider = lambda pid, cause: SupervisorDirective.Restart

    one_for_one = AllForOneStrategy(decider, 10, timedelta(seconds=20))
    await one_for_one.handle_failure(supervisor_data['supervisor'],
                                     supervisor_data['pid_child'],
                                     supervisor_data['restart_statistic'],
                                     exc,
                                     None)

    supervisor_data['supervisor'].restart_children \
        .assert_called_once_with(exc, children_pids)
def supervisor_data():
    supervisor = MockSupervisor()
    mailbox = DefaultMailbox(None, None, None)
    local_process = ActorProcess(mailbox)
    pid_child = PID()
    pid_child.address = 'address'
    pid_child.id = 'id'
    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
    }