Skip to content

Commit

Permalink
Test: add tests for corrupted list/nlist
Browse files Browse the repository at this point in the history
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
xiexingguo committed Dec 5, 2015
1 parent cda5c26 commit d4859ef
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/librados/TestCase.h
Expand Up @@ -206,4 +206,17 @@ class RadosTestECPP : public RadosTestPP {
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
23 changes: 23 additions & 0 deletions src/test/librados/list.cc
Expand Up @@ -17,6 +17,7 @@ typedef RadosTestNS LibRadosList;
typedef RadosTestPPNS LibRadosListPP;
typedef RadosTestECNS LibRadosListEC;
typedef RadosTestECPPNS LibRadosListECPP;
typedef RadosTestNP LibRadosListNP;

TEST_F(LibRadosList, ListObjects) {
char buf[128];
Expand Down Expand Up @@ -665,5 +666,27 @@ TEST_F(LibRadosListECPP, ListObjectsStartPP) {
}
}

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"
23 changes: 23 additions & 0 deletions src/test/librados/nlist.cc
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}

0 comments on commit d4859ef

Please sign in to comment.