]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/heartbeat_map.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / heartbeat_map.cc
CommitLineData
7c673cae
FG
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
7c673cae
FG
15#include "common/HeartbeatMap.h"
16#include "common/ceph_context.h"
17#include "common/config.h"
18#include "global/global_context.h"
19#include "gtest/gtest.h"
20
21using namespace ceph;
22
23TEST(HeartbeatMap, Healthy) {
24 HeartbeatMap hm(g_ceph_context);
25 heartbeat_handle_d *h = hm.add_worker("one", pthread_self());
26
f67539c2 27 hm.reset_timeout(h, ceph::make_timespan(9), ceph::make_timespan(18));
7c673cae 28 bool healthy = hm.is_healthy();
f67539c2 29 ASSERT_TRUE(healthy);
7c673cae
FG
30
31 hm.remove_worker(h);
32}
33
34TEST(HeartbeatMap, Unhealth) {
35 HeartbeatMap hm(g_ceph_context);
36 heartbeat_handle_d *h = hm.add_worker("one", pthread_self());
37
f67539c2 38 hm.reset_timeout(h, ceph::make_timespan(1), ceph::make_timespan(3));
7c673cae
FG
39 sleep(2);
40 bool healthy = hm.is_healthy();
f67539c2 41 ASSERT_FALSE(healthy);
7c673cae
FG
42
43 hm.remove_worker(h);
44}