]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/kv_test: Fix estimate functions
authorAdam Kupczyk <akupczyk@ibm.com>
Tue, 10 Oct 2023 09:04:39 +0000 (09:04 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Tue, 10 Oct 2023 09:08:21 +0000 (09:08 +0000)
We need to use random content to estimate DB size.
Otherwise, compression will cause DB to be unreasonably small.

Fixes: https://tracker.ceph.com/issues/63121
Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/test/objectstore/test_kv.cc

index 33ffd6ab3968c64e1579e2e54391f8caac2f6adf..95c712ceffa5a430506d8ed4656e94f67e4cc251 100644 (file)
 
 using namespace std;
 
+std::string gen_random_string(size_t size) {
+  std::string s;
+  for (size_t i = 0; i < size; i++) {
+    s.push_back(rand());
+  }
+  return s;
+}
+
 class KVTest : public ::testing::TestWithParam<const char*> {
 public:
   boost::scoped_ptr<KeyValueDB> db;
@@ -556,10 +564,11 @@ TEST_P(KVTest, RocksDB_estimate_size) {
   for(int test = 0; test < 20; test++)
   {
     KeyValueDB::Transaction t = db->get_transaction();
-    bufferlist v1;
-    v1.append(string(1000, '1'));
-    for (int i = 0; i < 100; i++)
+    for (int i = 0; i < 100; i++) {
+      bufferlist v1;
+      v1.append(gen_random_string(1000));
       t->set("A", to_string(rand()%100000), v1);
+    }
     db->submit_transaction_sync(t);
     db->compact();
 
@@ -588,10 +597,11 @@ TEST_P(KVTest, RocksDB_estimate_size_column_family) {
   for(int test = 0; test < 20; test++)
   {
     KeyValueDB::Transaction t = db->get_transaction();
-    bufferlist v1;
-    v1.append(string(1000, '1'));
-    for (int i = 0; i < 100; i++)
+    for (int i = 0; i < 100; i++) {
+      bufferlist v1;
+      v1.append(gen_random_string(1000));
       t->set("cf1", to_string(rand()%100000), v1);
+    }
     db->submit_transaction_sync(t);
     db->compact();