| | |
| | | do { |
| | | std::this_thread::yield(); |
| | | } while (count.load() < nreq); |
| | | client.StopAll(); |
| | | client.Stop(); |
| | | printf("request %s %d done ", topic.c_str(), count.load()); |
| | | }; |
| | | |
| | |
| | | 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"); |