MB-20852: ep_test_apis: report final value in wait_for_stat... 87/67887/8
authorDave Rigby <daver@couchbase.com>
Wed, 21 Sep 2016 12:32:14 +0000 (13:32 +0100)
committerDave Rigby <daver@couchbase.com>
Tue, 27 Sep 2016 13:49:11 +0000 (13:49 +0000)
Change-Id: I5aeae80ffcc0791701cf5982df4b11d00b288c8a
Reviewed-on: http://review.couchbase.org/67887
Reviewed-by: Manu Dhundi <manu@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
tests/ep_test_apis.cc

index 7703113..8dbe1c2 100644 (file)
@@ -1294,7 +1294,8 @@ public:
       maxWaitTime(wait_time_in_secs * 1000 * 1000),
       totalSleepTime(0) {}
 
-    void incrementAndAbortIfLimitReached(const useconds_t sleep_time)
+    void incrementAndAbortIfLimitReached(T last_value,
+                                         const useconds_t sleep_time)
     {
         totalSleepTime += sleep_time;
         if (totalSleepTime >= maxWaitTime) {
@@ -1303,7 +1304,8 @@ public:
             if (statKey != NULL) {
                 std::cerr << "(" << statKey << ")";
             }
-            std::cerr << "' " << compareName << " " << final << " - aborting."
+            std::cerr << "' " << compareName << " " << final
+                      << " (last value:" << last_value << ") - aborting."
                       << std::endl;
             abort();
         }
@@ -1321,13 +1323,17 @@ private:
 
 void wait_for_stat_change(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
                           const char *stat, int initial,
-                          const char *statkey,
+                          const char *stat_key,
                           const time_t max_wait_time_in_secs) {
     useconds_t sleepTime = 128;
-    WaitTimeAccumulator<int> accumulator("to change from", stat, statkey,
+    WaitTimeAccumulator<int> accumulator("to change from", stat, stat_key,
                                          initial, max_wait_time_in_secs);
-    while (get_int_stat(h, h1, stat, statkey) == initial) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_int_stat(h, h1, stat, stat_key);
+        if (current != initial) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
         decayingSleep(&sleepTime);
     }
 }
@@ -1338,8 +1344,12 @@ void wait_for_stat_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     useconds_t sleepTime = 128;
     WaitTimeAccumulator<int> accumulator("to be", stat, stat_key, final,
                                          max_wait_time_in_secs);
-    while (get_int_stat(h, h1, stat, stat_key) != final) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_int_stat(h, h1, stat, stat_key);
+        if (current == final) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
         decayingSleep(&sleepTime);
     }
 }
@@ -1352,8 +1362,12 @@ void wait_for_stat_to_be_gte(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     WaitTimeAccumulator<int> accumulator("to be greater or equal than", stat,
                                          stat_key, final,
                                          max_wait_time_in_secs);
-    while (get_int_stat(h, h1, stat, stat_key) < final) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_int_stat(h, h1, stat, stat_key);
+        if (current >= final) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
         decayingSleep(&sleepTime);
     }
 }
@@ -1366,8 +1380,12 @@ void wait_for_stat_to_be_lte(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     WaitTimeAccumulator<int> accumulator("to be less than or equal to", stat,
                                          stat_key, final,
                                          max_wait_time_in_secs);
-    while (get_int_stat(h, h1, stat, stat_key) > final) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_int_stat(h, h1, stat, stat_key);
+        if (current <= final) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
         decayingSleep(&sleepTime);
     }
 }
@@ -1379,10 +1397,14 @@ void wait_for_expired_items_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     WaitTimeAccumulator<int> accumulator("to be", "expired items",
                                          NULL, final,
                                          max_wait_time_in_secs);
-    while(get_int_stat(h, h1, "ep_expired_access") +
-          get_int_stat(h, h1, "ep_expired_compactor") +
-          get_int_stat(h, h1, "ep_expired_pager") != final) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_int_stat(h, h1, "ep_expired_access") +
+                       get_int_stat(h, h1, "ep_expired_compactor") +
+                       get_int_stat(h, h1, "ep_expired_pager");
+        if (current == final) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
         decayingSleep(&sleepTime);
     }
 }
@@ -1395,8 +1417,13 @@ void wait_for_str_stat_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     WaitTimeAccumulator<const char*> accumulator("to be", stat, stat_key,
                                                  final,
                                                  max_wait_time_in_secs);
-    while (get_str_stat(h, h1, stat, stat_key).compare(final) != 0) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_str_stat(h, h1, stat, stat_key);
+        if (current == final) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current.c_str(),
+                                                    sleepTime);
         decayingSleep(&sleepTime);
     }
 }
@@ -1408,8 +1435,12 @@ void wait_for_memory_usage_below(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     WaitTimeAccumulator<int> accumulator("to be below", "mem_used", NULL,
                                          mem_threshold,
                                          max_wait_time_in_secs);
-    while (get_int_stat(h, h1, "mem_used") > mem_threshold) {
-        accumulator.incrementAndAbortIfLimitReached(sleepTime);
+    for (;;) {
+        auto current = get_int_stat(h, h1, "mem_used");
+        if (current <= mem_threshold) {
+            break;
+        }
+        accumulator.incrementAndAbortIfLimitReached(current, sleepTime);
         decayingSleep(&sleepTime);
     }
 }