Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / heartbeat_map.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2011 New Dream Network
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #include "common/Mutex.h"
16 #include "common/HeartbeatMap.h"
17 #include "common/ceph_context.h"
18 #include "common/config.h"
19 #include "global/global_context.h"
20 #include "gtest/gtest.h"
21
22 using namespace ceph;
23
24 TEST(HeartbeatMap, Healthy) {
25   HeartbeatMap hm(g_ceph_context);
26   heartbeat_handle_d *h = hm.add_worker("one", pthread_self());
27
28   hm.reset_timeout(h, 9, 18);
29   bool healthy = hm.is_healthy();
30   ASSERT_EQ(healthy, true);
31
32   hm.remove_worker(h);
33 }
34
35 TEST(HeartbeatMap, Unhealth) {
36   HeartbeatMap hm(g_ceph_context);
37   heartbeat_handle_d *h = hm.add_worker("one", pthread_self());
38
39   hm.reset_timeout(h, 1, 3);
40   sleep(2);
41   bool healthy = hm.is_healthy();
42   ASSERT_EQ(healthy, false);
43
44   hm.remove_worker(h);
45 }