auto& ckpt_mgr = vb0->checkpointManager;
ckpt_mgr.createNewCheckpoint();
- /* Flush all items to the disk for a persistent bucket */
- if (bucketType == "persistent") {
- // EXPECT_EQ(1, engine->getKVBucket()->flushVBucket(vbid));
- setup_dcp_stream(); // [TODO]: Check why TearDown() crashes without this
- return; // [TODO]: Debug why flushVBucket does not work
- }
-
- /* Remove the old checkpoint */
+ /* Wait for removal of the old checkpoint, this also would imply that the
+ items are persisted (in case of persistent buckets) */
bool new_ckpt_created;
- EXPECT_EQ(numItems,
- ckpt_mgr.removeClosedUnrefCheckpoints(*vb0, new_ckpt_created));
+ std::chrono::microseconds uSleepTime(128);
+ while (static_cast<size_t>(numItems) !=
+ ckpt_mgr.removeClosedUnrefCheckpoints(*vb0, new_ckpt_created)) {
+ uSleepTime = decayingSleep(uSleepTime);
+ }
/* Set up a DCP stream for the backfill */
setup_dcp_stream();
mock_stream->transitionStateToBackfilling();
/* Wait for the backfill task to complete */
+ std::chrono::microseconds uSleepTime2(128);
while (numItems != mock_stream->getLastReadSeqno()) {
- usleep(10);
+ uSleepTime2 = decayingSleep(uSleepTime2);
}
/* Verify that all items are read in the backfill */
#include "test_helpers.h"
+#include <thread>
+
Item make_item(uint16_t vbid,
const StoredDocKey& key,
const std::string& value,
item.setVBucketId(vbid);
return item;
}
+
+std::chrono::microseconds decayingSleep(std::chrono::microseconds uSeconds) {
+ /* Max sleep time is slightly over a second */
+ static const std::chrono::microseconds maxSleepTime(0x1 << 20);
+ std::this_thread::sleep_for(uSeconds);
+ return std::min(uSeconds * 2, maxSleepTime);
+}
#include "item.h"
#include "programs/engine_testapp/mock_server.h"
+#include <chrono>
+
/// Creates an item with the given vbucket id, key and value.
Item make_item(
uint16_t vbid,
// Amount of time travel.
int by;
};
+
+/**
+ * Function to do an exponentially increasing, but max bounded, sleep.
+ * To do exponentially increasing sleep, must be called first with the starting
+ * sleep time and subsequently with the sleep time returned in the previous call
+ *
+ * @param uSeconds Desired sleep time in micro seconds
+ *
+ * @return indicates the next sleep time (doubled from the current value)
+ */
+std::chrono::microseconds decayingSleep(std::chrono::microseconds uSeconds);