lichao
2021-04-15 c64c54d8e75b9354dc49a7b6b2d326e7dd59eb37
utest/utest.cpp
@@ -99,7 +99,7 @@
   BHCenter center(shm);
   center.Start();
   std::this_thread::sleep_for(100ms);
   Sleep(100ms);
   std::atomic<uint64_t> total_count(0);
   std::atomic<ptime> last_time(Now() - seconds(1));
@@ -113,7 +113,8 @@
      for (auto &t : topics) {
         tlist.add_topic_list(t);
      }
      bool r = client.Subscribe(tlist, timeout);
      MsgCommonReply reply_body;
      bool r = client.Subscribe(tlist, reply_body, timeout);
      if (!r) {
         printf("client subscribe failed.\n");
      }
@@ -149,7 +150,7 @@
         MsgPublish pub;
         pub.set_topic(topic);
         pub.set_data(data);
         bool r = provider.Publish(pub, timeout);
         bool r = provider.Publish(pub, 0);
         if (!r) {
            static std::atomic<int> an(0);
            int n = ++an;
@@ -169,7 +170,7 @@
      part.push_back(topics[i]);
      threads.Launch(Sub, i, topics);
   }
   std::this_thread::sleep_for(100ms);
   Sleep(100ms);
   for (auto &topic : topics) {
      threads.Launch(Pub, topic);
   }
@@ -217,7 +218,7 @@
      std::atomic<int> count(0);
      std::string reply;
      auto onRecv = [&](const std::string &proc_id, const MsgRequestTopicReply &msg) {
      auto onRecv = [&](const BHMsgHead &head, const MsgRequestTopicReply &msg) {
         reply = msg.data();
         if (++count >= nreq) {
            printf("count: %d\n", count.load());
@@ -229,7 +230,8 @@
         MsgRequestTopic req;
         req.set_topic(topic);
         req.set_data("data " + std::to_string(i));
         if (!client.ClientAsyncRequest(req)) {
         std::string msg_id;
         if (!client.ClientAsyncRequest(req, msg_id)) {
            printf("client request failed\n");
            ++count;
         }
@@ -274,9 +276,9 @@
   ThreadManager clients, servers;
   std::vector<Topic> topics = {"topic1", "topic2"};
   servers.Launch(Server, "server", topics);
   std::this_thread::sleep_for(100ms);
   Sleep(100ms);
   for (auto &t : topics) {
      clients.Launch(Client, t, 1000 * 1);
      clients.Launch(Client, t, 1000 * 100);
   }
   clients.WaitAll();
   printf("clients done, server replyed: %ld\n", server_msg_count.load());
@@ -302,18 +304,16 @@
      };
      Check();
      for (int i = 0; i < 3; ++i) {
         std::this_thread::sleep_for(1s);
         Sleep(1s);
         Check();
      }
      printf("sleep 4\n");
      std::this_thread::sleep_for(4s);
      Sleep(4s);
      for (int i = 0; i < 2; ++i) {
         std::this_thread::sleep_for(1s);
         Sleep(1s);
         Check();
      }
   }
   printf("sleep 8\n");
   std::this_thread::sleep_for(8s);
   Sleep(8s);
}
inline int MyMin(int a, int b)
{