1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "test/librbd/test_mock_fixture.h"
5 #include "test/librbd/test_support.h"
6 #include "test/librbd/mock/MockImageCtx.h"
7 #include "test/librbd/mock/exclusive_lock/MockPolicy.h"
8 #include "librbd/io/ImageDispatchSpec.h"
9 #include "librbd/io/ImageRequestWQ.h"
10 #include "librbd/io/ImageRequest.h"
15 TEST_F(TestMockIoImageRequestWQ
, QosNoLimit
) {
16 librbd::ImageCtx
*ictx
;
17 ASSERT_EQ(0, open_image(m_image_name
, &ictx
));
19 MockTestImageCtx
mock_image_ctx(*ictx
);
21 MockImageDispatchSpec mock_queued_image_request
;
22 expect_was_throttled(mock_queued_image_request
, false);
23 expect_set_throttled(mock_queued_image_request
);
26 MockImageRequestWQ
mock_image_request_wq(&mock_image_ctx
, "io", 60, nullptr);
28 mock_image_request_wq
.apply_qos_limit(IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE
, 0,
31 expect_front(mock_image_request_wq
, &mock_queued_image_request
);
32 expect_is_refresh_request(mock_image_ctx
, false);
33 expect_is_write_op(mock_queued_image_request
, true);
34 expect_dequeue(mock_image_request_wq
, &mock_queued_image_request
);
35 ASSERT_TRUE(mock_image_request_wq
.invoke_dequeue() == &mock_queued_image_request
);
38 TEST_F(TestMockIoImageRequestWQ
, BPSQosNoBurst
) {
39 librbd::ImageCtx
*ictx
;
40 ASSERT_EQ(0, open_image(m_image_name
, &ictx
));
42 MockTestImageCtx
mock_image_ctx(*ictx
);
44 MockImageDispatchSpec mock_queued_image_request
;
45 expect_was_throttled(mock_queued_image_request
, false);
46 expect_set_throttled(mock_queued_image_request
);
49 MockImageRequestWQ
mock_image_request_wq(&mock_image_ctx
, "io", 60, nullptr);
51 mock_image_request_wq
.apply_qos_limit(IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE
, 1,
54 expect_front(mock_image_request_wq
, &mock_queued_image_request
);
55 expect_tokens_requested(mock_queued_image_request
, 2, true);
56 expect_dequeue(mock_image_request_wq
, &mock_queued_image_request
);
57 expect_all_throttled(mock_queued_image_request
, true);
58 expect_requeue_back(mock_image_request_wq
);
59 expect_signal(mock_image_request_wq
);
60 ASSERT_TRUE(mock_image_request_wq
.invoke_dequeue() == nullptr);
63 TEST_F(TestMockIoImageRequestWQ
, BPSQosWithBurst
) {
64 librbd::ImageCtx
*ictx
;
65 ASSERT_EQ(0, open_image(m_image_name
, &ictx
));
67 MockTestImageCtx
mock_image_ctx(*ictx
);
69 MockImageDispatchSpec mock_queued_image_request
;
70 expect_was_throttled(mock_queued_image_request
, false);
71 expect_set_throttled(mock_queued_image_request
);
74 MockImageRequestWQ
mock_image_request_wq(&mock_image_ctx
, "io", 60, nullptr);
76 mock_image_request_wq
.apply_qos_limit(IMAGE_DISPATCH_FLAG_QOS_BPS_THROTTLE
, 1,
79 expect_front(mock_image_request_wq
, &mock_queued_image_request
);
80 expect_tokens_requested(mock_queued_image_request
, 2, true);
81 expect_dequeue(mock_image_request_wq
, &mock_queued_image_request
);
82 expect_all_throttled(mock_queued_image_request
, true);
83 expect_requeue_back(mock_image_request_wq
);
84 expect_signal(mock_image_request_wq
);
85 ASSERT_TRUE(mock_image_request_wq
.invoke_dequeue() == nullptr);