From 65ef4d68321e56906920be75831b5e968f7abd7b Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 13 四月 2021 09:34:05 +0800 Subject: [PATCH] add heartbeat; refactor. --- utest/utest.cpp | 33 ++++++++++++++++++++++++++++++++- 1 files changed, 32 insertions(+), 1 deletions(-) diff --git a/utest/utest.cpp b/utest/utest.cpp index e0a9023..f127a8f 100644 --- a/utest/utest.cpp +++ b/utest/utest.cpp @@ -240,7 +240,7 @@ do { std::this_thread::yield(); } while (count.load() < nreq); - client.StopAll(); + client.Stop(); printf("request %s %d done ", topic.c_str(), count.load()); }; @@ -282,6 +282,37 @@ servers.WaitAll(); } +BOOST_AUTO_TEST_CASE(HeartbeatTest) +{ + const std::string shm_name("ShmHeartbeat"); + ShmRemover auto_remove(shm_name); + SharedMemory shm(shm_name, 1024 * 1024 * 50); + + BHCenter center(shm); + center.Start(); + + { + + DemoNode node("demo_node", shm); + auto Check = [&]() { + bool r = node.Heartbeat(100); + printf("hearbeat ret : %s\n", r ? "ok" : "failed"); + }; + Check(); + for (int i = 0; i < 3; ++i) { + std::this_thread::sleep_for(1s); + Check(); + } + printf("sleep 4\n"); + std::this_thread::sleep_for(4s); + for (int i = 0; i < 2; ++i) { + std::this_thread::sleep_for(1s); + Check(); + } + } + printf("sleep 8\n"); + std::this_thread::sleep_for(8s); +} inline int MyMin(int a, int b) { printf("MyMin\n"); -- Gitblit v1.8.0