]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: verify that librbd will periodically resend lock request
authorJason Dillaman <dillaman@redhat.com>
Thu, 7 May 2015 17:31:50 +0000 (13:31 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 5 Jun 2015 16:33:43 +0000 (12:33 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librbd/test_ImageWatcher.cc

index da84093f612a5da3ebb18cb85b6a070ea1d9b949..3046a3d07ec0a7c3f29fccfd16f2fc8822bfaf6b 100644 (file)
@@ -192,7 +192,8 @@ public:
     Mutex::Locker l(m_callback_lock);
     int r = 0;
     while (!m_aio_completions.empty() &&
-          m_aio_completion_restarts < m_expected_aio_restarts) {
+           (m_expected_aio_restarts == 0 ||
+           m_aio_completion_restarts < m_expected_aio_restarts)) {
       r = m_callback_cond.WaitInterval(ictx.cct, m_callback_lock,
                                       utime_t(10, 0));
       if (r != 0) {
@@ -601,6 +602,41 @@ TEST_F(TestImageWatcher, RequestLockTimedOut) {
   m_notify_acks = boost::assign::list_of(
     std::make_pair(NOTIFY_OP_REQUEST_LOCK, bufferlist()));
 
+  m_expected_aio_restarts = 1;
+  {
+    RWLock::WLocker l(ictx->owner_lock);
+    ictx->image_watcher->request_lock(
+      boost::bind(&TestImageWatcher::handle_restart_aio, this, ictx, _1),
+      create_aio_completion(*ictx));
+  }
+
+  ASSERT_TRUE(wait_for_notifies(*ictx));
+  NotifyOps expected_notify_ops;
+  expected_notify_ops += NOTIFY_OP_REQUEST_LOCK;
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+
+  ASSERT_TRUE(wait_for_aio_completions(*ictx));
+}
+
+TEST_F(TestImageWatcher, RequestLockIgnored) {
+  REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+  librbd::ImageCtx *ictx;
+  ASSERT_EQ(0, open_image(m_image_name, &ictx));
+  ASSERT_EQ(0, register_image_watch(*ictx));
+  ASSERT_EQ(0, lock_image(*ictx, LOCK_EXCLUSIVE,
+                         "auto " + stringify(m_watch_ctx->get_handle())));
+
+  m_notify_acks = boost::assign::list_of(
+    std::make_pair(NOTIFY_OP_REQUEST_LOCK, create_response_message(0)));
+
+  int orig_notify_timeout = ictx->cct->_conf->client_notify_timeout;
+  ictx->cct->_conf->set_val("client_notify_timeout", "0");
+  BOOST_SCOPE_EXIT( (ictx)(orig_notify_timeout) ) {
+    ictx->cct->_conf->set_val("client_notify_timeout",
+                              stringify(orig_notify_timeout));
+  } BOOST_SCOPE_EXIT_END;
+
   {
     RWLock::WLocker l(ictx->owner_lock);
     ictx->image_watcher->request_lock(
@@ -613,6 +649,11 @@ TEST_F(TestImageWatcher, RequestLockTimedOut) {
   expected_notify_ops += NOTIFY_OP_REQUEST_LOCK;
   ASSERT_EQ(expected_notify_ops, m_notifies);
 
+  // after the request times out -- it will be resent
+  ASSERT_TRUE(wait_for_notifies(*ictx));
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+
+  ASSERT_EQ(0, unlock_image());
   ASSERT_TRUE(wait_for_aio_completions(*ictx));
 }
 
@@ -628,6 +669,7 @@ TEST_F(TestImageWatcher, RequestLockTryLockRace) {
   m_notify_acks = boost::assign::list_of(
     std::make_pair(NOTIFY_OP_REQUEST_LOCK, create_response_message(0)));
 
+  m_expected_aio_restarts = 1;
   {
     RWLock::WLocker l(ictx->owner_lock);
     ictx->image_watcher->request_lock(
@@ -663,6 +705,7 @@ TEST_F(TestImageWatcher, RequestLockPreTryLockFailed) {
   ASSERT_EQ(0, open_image(m_image_name, &ictx));
   ASSERT_EQ(0, lock_image(*ictx, LOCK_SHARED, "manually 1234"));
 
+  m_expected_aio_restarts = 1;
   {
     RWLock::WLocker l(ictx->owner_lock);
     ictx->image_watcher->request_lock(