From 1908d3261ab05013466eb792a768fd2e4e016333 Mon Sep 17 00:00:00 2001 From: xiexingguo Date: Sun, 20 Dec 2015 17:50:26 +0800 Subject: [PATCH] Test: add tests for corrupted list/nlist process Signed-off-by: xie xingguo --- src/test/librados/TestCase.h | 13 +++++++++++++ src/test/librados/list.cc | 23 +++++++++++++++++++++++ src/test/librados/nlist.cc | 23 +++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/test/librados/TestCase.h b/src/test/librados/TestCase.h index bcef5a0901a..8e9a93d5351 100644 --- a/src/test/librados/TestCase.h +++ b/src/test/librados/TestCase.h @@ -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 diff --git a/src/test/librados/list.cc b/src/test/librados/list.cc index ff6a94911f2..eb65ded0aef 100644 --- a/src/test/librados/list.cc +++ b/src/test/librados/list.cc @@ -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" diff --git a/src/test/librados/nlist.cc b/src/test/librados/nlist.cc index 19ff73f4edf..c6fa82db765 100644 --- a/src/test/librados/nlist.cc +++ b/src/test/librados/nlist.cc @@ -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); +} + -- 2.47.3