blob: 40ca1ac17baec151f7b45e587f6ce7e3ef533578 (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/slobrok/backoff.h>
#include <vespa/log/log.h>
LOG_SETUP("backoff_test");
using slobrok::api::BackOff;
TEST_SETUP(Test);
//-----------------------------------------------------------------------------
int
Test::Main()
{
TEST_INIT("backoff_test");
BackOff one;
EXPECT_TRUE(one.shouldWarn());
EXPECT_EQUAL(0.500, one.get());
for (int i = 2; i < 41; i++) {
EXPECT_EQUAL(0.5 * i, one.get());
}
for (int i = 1; i < 1000; i++) {
EXPECT_EQUAL(20.0, one.get());
}
TEST_FLUSH();
BackOff two;
for (int i = 1; i < 50; i++) {
double expect = 0.5 * i;
if (expect > 20.0) expect = 20.0;
EXPECT_EQUAL(expect, two.get());
if (i == 1 || i == 7 || i == 18) {
EXPECT_TRUE(two.shouldWarn());
} else {
EXPECT_FALSE(two.shouldWarn());
}
}
two.reset();
for (int i = 1; i < 50; i++) {
double expect = 0.5 * i;
if (expect > 20.0) expect = 20.0;
EXPECT_EQUAL(expect, two.get());
if (i == 1 || i == 7 || i == 18) {
EXPECT_TRUE(two.shouldWarn());
} else {
EXPECT_FALSE(two.shouldWarn());
}
}
for (int i = 0; i < 50000; i++) {
EXPECT_EQUAL(20.0, two.get());
if ((i % 180) == 5) {
EXPECT_TRUE(two.shouldWarn());
} else {
EXPECT_FALSE(two.shouldWarn());
}
}
TEST_DONE();
}
|