]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/test_workqueue.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / test_workqueue.cc
index 0b3daeb05558c356ebd42105c9105877005637d6..d3354d633ca0f1a5557e8d9f5161a121af273651 100644 (file)
@@ -3,6 +3,8 @@
 #include "common/WorkQueue.h"
 #include "common/ceph_argparse.h"
 
+using namespace std;
+
 TEST(WorkQueue, StartStop)
 {
   ThreadPool tp(g_ceph_context, "foo", "tp_foo", 10, "");
@@ -53,3 +55,44 @@ TEST(WorkQueue, Resize)
   sleep(1);
   tp.stop();
 }
+
+class twq : public ThreadPool::WorkQueue<int> {
+public:
+    twq(time_t timeout, time_t suicide_timeout, ThreadPool *tp)
+        : ThreadPool::WorkQueue<int>("test_wq", ceph::make_timespan(timeout), ceph::make_timespan(suicide_timeout), tp) {}
+
+    bool _enqueue(int* item) override {
+        return true;
+    }
+    void _dequeue(int* item) override {
+        ceph_abort();
+    }
+    bool _empty() override {
+        return true;
+    }
+    int *_dequeue() override {
+        return nullptr;
+    }
+    void _process(int *osr, ThreadPool::TPHandle &handle) override {
+    }
+    void _process_finish(int *osr) override {
+    }
+    void _clear() override {
+    }
+};
+
+TEST(WorkQueue, change_timeout){
+    ThreadPool tp(g_ceph_context, "bar", "tp_bar", 2, "filestore_op_threads");
+    tp.start();
+    twq wq(2, 20, &tp);
+    // check timeout and suicide
+    ASSERT_EQ(ceph::make_timespan(2), wq.timeout_interval);
+    ASSERT_EQ(ceph::make_timespan(20), wq.suicide_interval);
+
+    // change the timeout and suicide and then check them
+    wq.set_timeout(4);
+    wq.set_suicide_timeout(40);
+    ASSERT_EQ(ceph::make_timespan(4), wq.timeout_interval);
+    ASSERT_EQ(ceph::make_timespan(40), wq.suicide_interval);
+    tp.stop();
+}