]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Test: add tests for corrupted list/nlist process 6639/head
authorxiexingguo <xie.xingguo@zte.com.cn>
Sun, 20 Dec 2015 09:50:26 +0000 (17:50 +0800)
committerxiexingguo <xie.xingguo@zte.com.cn>
Sun, 20 Dec 2015 09:50:26 +0000 (17:50 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/test/librados/TestCase.h
src/test/librados/list.cc
src/test/librados/nlist.cc

index bcef5a0901a9977112255d2863bd45f6cf68b86d..8e9a93d5351b64a074aa39d10e43cb41ef3b931b 100644 (file)
@@ -206,4 +206,17 @@ protected:
   std::string nspace;
   uint64_t alignment;
 };
+
+/**
+ * Test case without creating a temporary pool in advance.
+ * This is necessary for scenarios such that we need to
+ * manually create a pool, start some long-runing tasks and
+ * then the related pool is suddenly gone.
+ */
+class RadosTestNP: public ::testing::Test {
+public:
+  RadosTestNP() {}
+  virtual ~RadosTestNP() {}
+};
+
 #endif
index ff6a94911f2121c1769a10d82e2e61d4708c81cc..eb65ded0aefc497290bf981657338a4705326678 100644 (file)
@@ -19,6 +19,7 @@ typedef RadosTestNS LibRadosList;
 typedef RadosTestPPNS LibRadosListPP;
 typedef RadosTestECNS LibRadosListEC;
 typedef RadosTestECPPNS LibRadosListECPP;
+typedef RadosTestNP LibRadosListNP;
 
 TEST_F(LibRadosList, ListObjects) {
   char buf[128];
@@ -883,5 +884,27 @@ TEST_F(LibRadosListPP, EnumerateObjectsSplitPP) {
   ASSERT_EQ(n_objects, saw_obj.size());
 }
 
+TEST_F(LibRadosListNP, ListObjectsError) {
+  std::string pool_name;
+  rados_t cluster;
+  rados_ioctx_t ioctx;
+  pool_name = get_temp_pool_name();
+  ASSERT_EQ("", create_one_pool(pool_name, &cluster));
+  ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
+  char buf[128];
+  memset(buf, 0xcc, sizeof(buf));
+  rados_ioctx_set_namespace(ioctx, "");
+  ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
+  ASSERT_EQ(0, rados_pool_delete(cluster, pool_name.c_str()));
+  
+  rados_list_ctx_t ctx;
+  ASSERT_EQ(0, rados_objects_list_open(ioctx, &ctx));
+  const char *entry;
+  ASSERT_EQ(-ENOENT, rados_objects_list_next(ctx, &entry, NULL));
+  rados_objects_list_close(ctx);
+  rados_ioctx_destroy(ioctx);
+  rados_shutdown(cluster);
+}
+
 #pragma GCC diagnostic pop
 #pragma GCC diagnostic warning "-Wpragmas"
index 19ff73f4edfd7fcbc721c7e59ac21b9a762460cd..c6fa82db7651e6138ab563f1b07d50b105c81f1d 100644 (file)
@@ -16,6 +16,7 @@ typedef RadosTestNS LibRadosList;
 typedef RadosTestPPNS LibRadosListPP;
 typedef RadosTestECNS LibRadosListEC;
 typedef RadosTestECPPNS LibRadosListECPP;
+typedef RadosTestNP LibRadosListNP;
 
 TEST_F(LibRadosList, ListObjects) {
   char buf[128];
@@ -730,3 +731,25 @@ TEST_F(LibRadosListPP, ListObjectsFilterPP) {
   ASSERT_TRUE(foundit);
 }
 
+TEST_F(LibRadosListNP, ListObjectsError) {
+  std::string pool_name;
+  rados_t cluster;
+  rados_ioctx_t ioctx;
+  pool_name = get_temp_pool_name();
+  ASSERT_EQ("", create_one_pool(pool_name, &cluster));
+  ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
+  char buf[128];
+  memset(buf, 0xcc, sizeof(buf));
+  rados_ioctx_set_namespace(ioctx, "");
+  ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
+  ASSERT_EQ(0, rados_pool_delete(cluster, pool_name.c_str()));
+  
+  rados_list_ctx_t ctx;
+  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
+  const char *entry;
+  ASSERT_EQ(-ENOENT, rados_nobjects_list_next(ctx, &entry, NULL, NULL));
+  rados_nobjects_list_close(ctx);
+  rados_ioctx_destroy(ioctx);
+  rados_shutdown(cluster);
+}
+