Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / test_workqueue.cc
1 #include "gtest/gtest.h"
2
3 #include "common/WorkQueue.h"
4 #include "common/ceph_argparse.h"
5
6 TEST(WorkQueue, StartStop)
7 {
8   ThreadPool tp(g_ceph_context, "foo", "tp_foo", 10, "");
9   
10   tp.start();
11   tp.pause();
12   tp.pause_new();
13   tp.unpause();
14   tp.unpause();
15   tp.drain();
16   tp.stop();
17 }
18
19 TEST(WorkQueue, Resize)
20 {
21   ThreadPool tp(g_ceph_context, "bar", "tp_bar", 2, "osd_peering_wq_threads");
22   
23   tp.start();
24
25   sleep(1);
26   ASSERT_EQ(2, tp.get_num_threads());
27
28   g_conf->set_val("osd peering wq threads", "5");
29   g_conf->apply_changes(&cout);
30   sleep(1);
31   ASSERT_EQ(5, tp.get_num_threads());
32
33   g_conf->set_val("osd peering wq threads", "3");
34   g_conf->apply_changes(&cout);
35   sleep(1);
36   ASSERT_EQ(3, tp.get_num_threads());
37
38   g_conf->set_val("osd peering wq threads", "0");
39   g_conf->apply_changes(&cout);
40   sleep(1);
41   ASSERT_EQ(0, tp.get_num_threads());
42
43   g_conf->set_val("osd peering wq threads", "15");
44   g_conf->apply_changes(&cout);
45   sleep(1);
46   ASSERT_EQ(15, tp.get_num_threads());
47
48   g_conf->set_val("osd peering wq threads", "-1");
49   g_conf->apply_changes(&cout);
50   sleep(1);
51   ASSERT_EQ(15, tp.get_num_threads());
52
53   sleep(1);
54   tp.stop();
55 }