Example #1
0
def test_flusher_message(spawn, joinall):
    """
    Test that we email a simple record appropriately.
    """
    template_dir = os.path.join(os.path.dirname(__file__), '..')

    pager_window = 5
    pager_limit = 10

    message_rate = MessageRate(pager_window, pager_limit)

    spawn_ret_val = object()
    spawn.return_value = spawn_ret_val

    env = Environment(loader=FileSystemLoader(template_dir))
    message_buffer = MessageBuffer(env.get_template('subject-template.txt'),
                               env.get_template('body-template.txt'))

    message = UniqueMessage('module', 'funcName', 'filename', 'message',
                            'pathname', 'lineno', 'exc_text', 'kind')

    message_buffer.add(message, 'source')

    flusher(message_buffer, message_rate)
    spawn.assert_called_once_with(mailer, ANY, ANY, ANY)

    # We shouldn't have done anything
    eq_(1, spawn.call_count)
    eq_(1, joinall.call_count)
    joinall.assert_called_once_with([spawn_ret_val])
Example #2
0
def test_flusher_rate_excede(spawn, joinall, pager, mailer):
    """
    Test that we complain extra loudly if we get too many errors.
    """
    template_dir = os.path.join(os.path.dirname(__file__), '..')

    pager_window = 5
    pager_limit = 10

    message_rate = MessageRate(pager_window, pager_limit)

    spawn_ret_val = object()
    spawn.return_value = spawn_ret_val

    env = Environment(loader=FileSystemLoader(template_dir))
    message_buffer = MessageBuffer(env.get_template('subject-template.txt'),
                               env.get_template('body-template.txt'))

    for i in range(pager_limit + 1):
        message_buffer.add(UniqueMessage('module', 'funcName', 'filename',
                                         'message', 'pathname', i,
                                         'exc_text', 'kind'),
                           'source')

    flusher(message_buffer, message_rate)
    eq_([call(pager, pager_limit + 1),
         call(mailer, ANY, ANY, ANY)],
        spawn.call_args_list)

    # We shouldn't have done anything
    eq_(2, spawn.call_count)
    eq_(1, joinall.call_count)
    joinall.assert_called_once_with([spawn_ret_val] * 2)
Example #3
0
def test_flusher_none(spawn, joinall):
    """
    Test that we don't do anything if there is nothing to do.
    """
    template_dir = os.path.join(os.path.dirname(__file__), '..')

    pager_window = 5
    pager_limit = 10

    message_rate = MessageRate(pager_window, pager_limit)

    env = Environment(loader=FileSystemLoader(template_dir))
    message_buffer = MessageBuffer(env.get_template('subject-template.txt'),
                               env.get_template('body-template.txt'))
    flusher(message_buffer, message_rate)

    # We shouldn't have done anything
    eq_(0, spawn.call_count)
    eq_(0, joinall.call_count)