aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/tests/retrypolicy/retrypolicy.cpp
blob: 059c017f46ae743a984f2d4774a803abcc224301 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/messagebus/errorcode.h>
#include <vespa/messagebus/routing/retrytransienterrorspolicy.h>
#include <vespa/vespalib/testkit/testapp.h>

using namespace mbus;

TEST_SETUP(Test);

int
Test::Main()
{
    TEST_INIT("retrypolicy_test");
    constexpr double DELAY(0.001);
    RetryTransientErrorsPolicy policy;
    policy.setBaseDelay(DELAY);
    EXPECT_EQUAL(0.0, policy.getRetryDelay(0));
    EXPECT_EQUAL(0.0, policy.getRetryDelay(1));
    for (uint32_t j = 2; j < 15; ++j) {
        EXPECT_EQUAL(DELAY*(1 << (j-1)), policy.getRetryDelay(j));
    }
    EXPECT_EQUAL(10.0, policy.getRetryDelay(15));
    EXPECT_EQUAL(10.0, policy.getRetryDelay(20));
    for (uint32_t i = 0; i < 5; ++i) {
        for (uint32_t j = ErrorCode::NONE; j < ErrorCode::ERROR_LIMIT; ++j) {
            policy.setEnabled(true);
            if (j < ErrorCode::FATAL_ERROR) {
                EXPECT_TRUE(policy.canRetry(j));
            } else {
                EXPECT_TRUE(!policy.canRetry(j));
            }
            policy.setEnabled(false);
            EXPECT_TRUE(!policy.canRetry(j));
        }
    }

    TEST_DONE();
}