summaryrefslogtreecommitdiffstats
path: root/src/test/librbd/test_mock_ExclusiveLock.cc
diff options
context:
space:
mode:
authorJason Dillaman <dillaman@redhat.com>2016-08-17 20:58:22 +0200
committerJason Dillaman <dillaman@redhat.com>2016-08-23 18:23:07 +0200
commit583ac91872859e81d68c9d346516522c6aa1614c (patch)
tree7550fd0c05aefc6e9d55a923f799e6a72f212d04 /src/test/librbd/test_mock_ExclusiveLock.cc
parentlibrbd: image state machine now has hooks for lock requests (diff)
downloadceph-583ac91872859e81d68c9d346516522c6aa1614c.tar.xz
ceph-583ac91872859e81d68c9d346516522c6aa1614c.zip
librbd: interlock image refresh and lock operations
Fixes: http://tracker.ceph.com/issues/16773 Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Diffstat (limited to 'src/test/librbd/test_mock_ExclusiveLock.cc')
-rw-r--r--src/test/librbd/test_mock_ExclusiveLock.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/librbd/test_mock_ExclusiveLock.cc b/src/test/librbd/test_mock_ExclusiveLock.cc
index 26b066a88d3..821f857b769 100644
--- a/src/test/librbd/test_mock_ExclusiveLock.cc
+++ b/src/test/librbd/test_mock_ExclusiveLock.cc
@@ -4,6 +4,7 @@
#include "test/librbd/test_mock_fixture.h"
#include "test/librbd/test_support.h"
#include "test/librbd/mock/MockImageCtx.h"
+#include "test/librbd/mock/MockImageState.h"
#include "librbd/ExclusiveLock.h"
#include "librbd/exclusive_lock/AcquireRequest.h"
#include "librbd/exclusive_lock/ReacquireRequest.h"
@@ -129,9 +130,11 @@ public:
void expect_acquire_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockAcquireRequest &acquire_request, int r) {
expect_get_watch_handle(mock_image_ctx);
+ expect_prepare_lock(mock_image_ctx);
EXPECT_CALL(acquire_request, send())
.WillOnce(DoAll(FinishLockUnlock(&acquire_request),
FinishRequest(&acquire_request, r, &mock_image_ctx)));
+ expect_handle_prepare_lock_complete(mock_image_ctx);
if (r == 0) {
expect_notify_acquired_lock(mock_image_ctx);
expect_unblock_writes(mock_image_ctx);
@@ -141,9 +144,15 @@ public:
void expect_release_lock(MockExclusiveLockImageCtx &mock_image_ctx,
MockReleaseRequest &release_request, int r,
bool shutting_down = false) {
+ if (!shutting_down) {
+ expect_prepare_lock(mock_image_ctx);
+ }
EXPECT_CALL(release_request, send())
.WillOnce(DoAll(FinishLockUnlock(&release_request),
FinishRequest(&release_request, r, &mock_image_ctx)));
+ if (!shutting_down) {
+ expect_handle_prepare_lock_complete(mock_image_ctx);
+ }
if (r == 0) {
if (shutting_down) {
expect_unblock_writes(mock_image_ctx);
@@ -188,6 +197,17 @@ public:
.WillOnce(CompleteContext(0, mock_image_ctx.image_ctx->op_work_queue));
}
+ void expect_prepare_lock(MockExclusiveLockImageCtx &mock_image_ctx) {
+ EXPECT_CALL(*mock_image_ctx.state, prepare_lock(_))
+ .WillOnce(Invoke([](Context *on_ready) {
+ on_ready->complete(0);
+ }));
+ }
+
+ void expect_handle_prepare_lock_complete(MockExclusiveLockImageCtx &mock_image_ctx) {
+ EXPECT_CALL(*mock_image_ctx.state, handle_prepare_lock_complete());
+ }
+
int when_init(MockExclusiveLockImageCtx &mock_image_ctx,
MockExclusiveLock &exclusive_lock) {
C_SaferCond ctx;
@@ -551,16 +571,20 @@ TEST_F(TestMockExclusiveLock, ConcurrentRequests) {
MockAcquireRequest try_lock_acquire;
C_SaferCond wait_for_send_ctx1;
expect_get_watch_handle(mock_image_ctx);
+ expect_prepare_lock(mock_image_ctx);
EXPECT_CALL(try_lock_acquire, send())
.WillOnce(Notify(&wait_for_send_ctx1));
+ expect_handle_prepare_lock_complete(mock_image_ctx);
MockAcquireRequest request_acquire;
expect_acquire_lock(mock_image_ctx, request_acquire, 0);
MockReleaseRequest release;
C_SaferCond wait_for_send_ctx2;
+ expect_prepare_lock(mock_image_ctx);
EXPECT_CALL(release, send())
.WillOnce(Notify(&wait_for_send_ctx2));
+ expect_handle_prepare_lock_complete(mock_image_ctx);
expect_notify_released_lock(mock_image_ctx);
expect_is_lock_request_needed(mock_image_ctx, false);