Ejemplo n.º 1
0
void
sub_seconds(ha_time_t * a_time, int extra)
{
    if (extra < 0) {
        add_seconds(a_time, -extra);
    } else {
        do_sub_time_field(a_time, seconds, extra, 60, sub_minutes);
    }
}
// @brief
//     The first element of 'expected_retry_times' shall be 0
static void run_and_verify_should_retry_times(RETRY_CONTROL_HANDLE handle, int* expected_retry_times, int number_of_elements, unsigned int max_retry_time_in_secs)
{
    time_t current_time = TEST_current_time;
    time_t first_time = INDEFINITE_TIME;
    time_t last_time = INDEFINITE_TIME;
    unsigned int secs_since_first_try = 0;
    unsigned int secs_since_last_try = 0;
    RETRY_ACTION expected_retry_action = RETRY_ACTION_RETRY_NOW;

    run_and_verify_should_retry(handle, first_time, last_time, current_time, secs_since_first_try, secs_since_last_try, expected_retry_action, true);

    first_time = current_time;
    last_time = current_time;

    int i;
    for (i = 1; i < number_of_elements; i++)
    {
        // RETRY_LATER time test
        int half_secs_since_last_try = (expected_retry_times[i] - expected_retry_times[i - 1]) / 2;

        if (half_secs_since_last_try > 0 && half_secs_since_last_try != expected_retry_times[i])
        {
            unsigned int half_secs_since_first_try = secs_since_first_try + half_secs_since_last_try;
            time_t half_current_time = add_seconds(current_time, half_secs_since_last_try);
            expected_retry_action = (half_secs_since_first_try < max_retry_time_in_secs ? RETRY_ACTION_RETRY_LATER : RETRY_ACTION_STOP_RETRYING);

            run_and_verify_should_retry(handle, first_time, last_time, half_current_time, half_secs_since_first_try, half_secs_since_last_try, expected_retry_action, false);
        }

        // RETRY_NOW/STOP_RETRYING time test
        secs_since_last_try = expected_retry_times[i];
        secs_since_first_try += expected_retry_times[i];
        current_time = add_seconds(current_time, secs_since_last_try);
        expected_retry_action = (secs_since_first_try < max_retry_time_in_secs ? RETRY_ACTION_RETRY_NOW : RETRY_ACTION_STOP_RETRYING);

        run_and_verify_should_retry(handle, first_time, last_time, current_time, secs_since_first_try, secs_since_last_try, expected_retry_action, false);

        if (expected_retry_action == RETRY_ACTION_RETRY_NOW)
        {
            last_time = current_time;
        }
    }
}