From 1bf058199a13783e227c0e87ea6f3244f3560cfd Mon Sep 17 00:00:00 2001 From: "J. Eric Ivancich" Date: Tue, 17 Aug 2021 17:35:19 -0400 Subject: [PATCH] test/rgw: fix and add to rgw/cls bi_list tests Make sure marker is cleared. Put end-of-list check inside the conditional with the rest of the test. Add some additional testing. Signed-off-by: J. Eric Ivancich --- src/test/cls_rgw/test_cls_rgw.cc | 84 ++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/src/test/cls_rgw/test_cls_rgw.cc b/src/test/cls_rgw/test_cls_rgw.cc index d150097fab4da..48c0ff7e309e2 100644 --- a/src/test/cls_rgw/test_cls_rgw.cc +++ b/src/test/cls_rgw/test_cls_rgw.cc @@ -562,14 +562,14 @@ TEST_F(cls_rgw, bi_list) cls_rgw_bucket_init_index(op); ASSERT_EQ(0, ioctx.operate(bucket_oid, &op)); - string name; - string marker; + const std::string empty_name_filter; uint64_t max = 10; - list entries; + std::list entries; bool is_truncated; + std::string marker; - int ret = cls_rgw_bi_list(ioctx, bucket_oid, name, marker, max, &entries, - &is_truncated); + int ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, max, + &entries, &is_truncated); ASSERT_EQ(ret, 0); ASSERT_EQ(entries.size(), 0u) << "The listing of an empty bucket as 0 entries."; @@ -578,7 +578,7 @@ TEST_F(cls_rgw, bi_list) uint64_t epoch = 1; uint64_t obj_size = 1024; - uint64_t num_objs = 35; + const uint64_t num_objs = 35; for (uint64_t i = 0; i < num_objs; i++) { string obj = str_int(i % 4 ? "obj" : "об'єкт", i); @@ -594,8 +594,8 @@ TEST_F(cls_rgw, bi_list) RGW_BILOG_FLAG_VERSIONED_OP); } - ret = cls_rgw_bi_list(ioctx, bucket_oid, name, marker, num_objs + 10, &entries, - &is_truncated); + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, num_objs + 10, + &entries, &is_truncated); ASSERT_EQ(ret, 0); if (is_truncated) { ASSERT_LT(entries.size(), num_objs); @@ -606,9 +606,10 @@ TEST_F(cls_rgw, bi_list) uint64_t num_entries = 0; is_truncated = true; + marker.clear(); while(is_truncated) { - ret = cls_rgw_bi_list(ioctx, bucket_oid, name, marker, max, &entries, - &is_truncated); + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, max, + &entries, &is_truncated); ASSERT_EQ(ret, 0); if (is_truncated) { ASSERT_LT(entries.size(), num_objs - num_entries); @@ -619,8 +620,9 @@ TEST_F(cls_rgw, bi_list) marker = entries.back().idx; } - ret = cls_rgw_bi_list(ioctx, bucket_oid, name, marker, max, &entries, - &is_truncated); + // try with marker as final entry + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, max, + &entries, &is_truncated); ASSERT_EQ(ret, 0); ASSERT_EQ(entries.size(), 0u); ASSERT_EQ(is_truncated, false); @@ -631,8 +633,8 @@ TEST_F(cls_rgw, bi_list) is_truncated = true; marker.clear(); while(is_truncated) { - ret = cls_rgw_bi_list(ioctx, bucket_oid, name, marker, max, &entries, - &is_truncated); + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, max, + &entries, &is_truncated); ASSERT_EQ(ret, 0); if (is_truncated) { ASSERT_LT(entries.size(), num_objs - num_entries); @@ -642,13 +644,57 @@ TEST_F(cls_rgw, bi_list) num_entries += entries.size(); marker = entries.back().idx; } + + // try with marker as final entry + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, max, + &entries, &is_truncated); + ASSERT_EQ(ret, 0); + ASSERT_EQ(entries.size(), 0u); + ASSERT_EQ(is_truncated, false); } - ret = cls_rgw_bi_list(ioctx, bucket_oid, name, marker, max, &entries, - &is_truncated); - ASSERT_EQ(ret, 0); - ASSERT_EQ(entries.size(), 0u); - ASSERT_EQ(is_truncated, false); + // test with name filters; pairs contain filter and expected number of elements returned + const std::list> filters_results = + { { str_int("obj", 9), 1 }, + { str_int("об'єкт", 8), 1 }, + { str_int("obj", 8), 0 } }; + for (const auto& filter_result : filters_results) { + is_truncated = true; + entries.clear(); + marker.clear(); + + ret = cls_rgw_bi_list(ioctx, bucket_oid, filter_result.first, marker, max, + &entries, &is_truncated); + + ASSERT_EQ(ret, 0) << "bi list test with name filters should succeed"; + ASSERT_EQ(entries.size(), filter_result.second) << + "bi list test with filters should return the correct number of results"; + ASSERT_EQ(is_truncated, false) << + "bi list test with filters should return correct truncation indicator"; + } + + // test whether combined segment count is correcgt + is_truncated = false; + entries.clear(); + marker.clear(); + + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, num_objs - 1, + &entries, &is_truncated); + ASSERT_EQ(ret, 0) << "combined segment count should succeed"; + ASSERT_EQ(entries.size(), num_objs - 1) << + "combined segment count should return the correct number of results"; + ASSERT_EQ(is_truncated, true) << + "combined segment count should return correct truncation indicator"; + + + marker = entries.back().idx; // advance marker + ret = cls_rgw_bi_list(ioctx, bucket_oid, empty_name_filter, marker, num_objs - 1, + &entries, &is_truncated); + ASSERT_EQ(ret, 0) << "combined segment count should succeed"; + ASSERT_EQ(entries.size(), 1) << + "combined segment count should return the correct number of results"; + ASSERT_EQ(is_truncated, false) << + "combined segment count should return correct truncation indicator"; } /* test garbage collection */ -- 2.39.5