summaryrefslogtreecommitdiff
path: root/src/mongo/db/free_mon
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-10-03 02:32:41 +0000
committerevergreen <evergreen@mongodb.com>2019-10-03 02:32:41 +0000
commit2961e15b5fd4534b324d78557afcf795aba056b6 (patch)
tree8fe3d5b1a17dc61a4935e458bdf36a91f09cc536 /src/mongo/db/free_mon
parentef5c6b85dd873b69a12d919932e54c7b6711b14d (diff)
downloadmongo-2961e15b5fd4534b324d78557afcf795aba056b6.tar.gz
SERVER-43767 fix free_mon_controller_test.cpp
Diffstat (limited to 'src/mongo/db/free_mon')
-rw-r--r--src/mongo/db/free_mon/free_mon_controller_test.cpp72
1 files changed, 60 insertions, 12 deletions
diff --git a/src/mongo/db/free_mon/free_mon_controller_test.cpp b/src/mongo/db/free_mon/free_mon_controller_test.cpp
index 4db1bfa3c44..13939a35142 100644
--- a/src/mongo/db/free_mon/free_mon_controller_test.cpp
+++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp
@@ -73,6 +73,12 @@
namespace mongo {
namespace {
+auto makeRandom() {
+ auto seed = SecureRandom::create()->nextInt64();
+ unittest::log() << "PseudoRandom(" << std::showbase << std::hex << seed << std::dec
+ << std::noshowbase << ")";
+ return PseudoRandom(seed);
+}
class FreeMonMetricsCollectorMock : public FreeMonCollectorInterface {
public:
@@ -455,7 +461,7 @@ repl::ReplicationCoordinatorMock* FreeMonControllerTest::_getReplCoord() const {
// Positive: Ensure deadlines sort properly
TEST(FreeMonRetryTest, TestRegistration) {
- PseudoRandom random(0);
+ auto random = makeRandom();
RegistrationRetryCounter counter(random);
counter.reset();
@@ -480,20 +486,47 @@ TEST(FreeMonRetryTest, TestRegistration) {
}
// Validate max timeout
- for (int j = 0; j < 3; j++) {
- // Fail requests
- for (int i = 1; i <= 163; ++i) {
- ASSERT_TRUE(counter.incrementError());
+
+ auto characterizeJitter = [](Seconds jitter1, Seconds jitter2) {
+ static constexpr size_t kStage1Retries = 10;
+ static constexpr auto kTMax = Days{2};
+ auto t = Seconds(0);
+ auto base = Seconds(1);
+ size_t i = 0;
+ for (; t < kTMax; ++i) {
+ if (i < kStage1Retries) {
+ base *= 2;
+ t += base + jitter1;
+ } else {
+ t += base + jitter2;
+ }
}
- ASSERT_FALSE(counter.incrementError());
+ return i;
+ };
+ // If jitter is small as possible, we'd expect trueMax increments before false.
+ const auto trueMax = characterizeJitter(Seconds{2}, Seconds{60});
+ // If jitter is large as possible, we'd expect trueMin increments before false.
+ const auto trueMin = characterizeJitter(Seconds{9}, Seconds{119});
+
+ // unittest::log() << "trueMin:" << trueMin;
+ // unittest::log() << "trueMax:" << trueMax;
+ for (int j = 0; j < 30; j++) {
+ // std::cout << "j: " << j << "\n";
+ // Fail requests
+ size_t trueCount = 0;
+ while (counter.incrementError()) {
+ ++trueCount;
+ }
+ ASSERT_GTE(trueCount, trueMin);
+ ASSERT_LTE(trueCount, trueMax);
counter.reset();
}
}
// Positive: Ensure deadlines sort properly
TEST(FreeMonRetryTest, TestMetrics) {
- PseudoRandom random(0);
+ auto random = makeRandom();
MetricsRetryCounter counter(random);
counter.reset();
@@ -519,13 +552,28 @@ TEST(FreeMonRetryTest, TestMetrics) {
}
// Validate max timeout
- for (int j = 0; j < 3; j++) {
- // Fail requests
- for (int i = 1; i < 9456; ++i) {
- ASSERT_TRUE(counter.incrementError());
+ static size_t expectation = [] {
+ // There's technically a jitter in the MetricsRetryCounter but its default
+ // magnitude rounds to 0, so we make an exact expectation.
+ size_t iters = 0;
+ static constexpr auto kDurationMax = Days{7};
+ auto t = Seconds{0};
+ auto base = Seconds{1};
+ for (; t < kDurationMax; ++iters) {
+ if (iters < 6)
+ base *= 2;
+ t += base;
}
- ASSERT_FALSE(counter.incrementError());
+ return iters;
+ }();
+ for (int j = 0; j < 30; j++) {
+ // Fail requests
+ int iters = 0;
+ while (counter.incrementError()) {
+ ++iters;
+ }
+ ASSERT_EQ(iters, expectation);
counter.reset();
}
}