当前位置: 首页>>代码示例>>C++>>正文


C++ EventBase::setMaxLatency方法代码示例

本文整理汇总了C++中EventBase::setMaxLatency方法的典型用法代码示例。如果您正苦于以下问题:C++ EventBase::setMaxLatency方法的具体用法?C++ EventBase::setMaxLatency怎么用?C++ EventBase::setMaxLatency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventBase的用法示例。


在下文中一共展示了EventBase::setMaxLatency方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: timeouts

/**
 * Verify that idle time is correctly accounted for when decaying our loop
 * time.
 *
 * This works by creating a high loop time (via usleep), expecting a latency
 * callback with known value, and then scheduling a timeout for later. This
 * later timeout is far enough in the future that the idle time should have
 * caused the loop time to decay.
 */
TEST(EventBaseTest, IdleTime) {
  EventBase eventBase;
  eventBase.setLoadAvgMsec(1000);
  eventBase.resetLoadAvg(5900.0);
  std::deque<uint64_t> timeouts0(4, 8080);
  timeouts0.push_front(8000);
  timeouts0.push_back(14000);
  IdleTimeTimeoutSeries tos0(&eventBase, timeouts0);
  std::deque<uint64_t> timeouts(20, 20);
  std::unique_ptr<IdleTimeTimeoutSeries> tos;
  int64_t testStart = duration_cast<microseconds>(
    std::chrono::steady_clock::now().time_since_epoch()).count();
  bool hostOverloaded = false;

  int latencyCallbacks = 0;
  eventBase.setMaxLatency(6000, [&]() {
    ++latencyCallbacks;

    switch (latencyCallbacks) {
    case 1:
      if (tos0.getTimeouts() < 6) {
        // This could only happen if the host this test is running
        // on is heavily loaded.
        int64_t maxLatencyReached = duration_cast<microseconds>(
            std::chrono::steady_clock::now().time_since_epoch()).count();
        ASSERT_LE(43800, maxLatencyReached - testStart);
        hostOverloaded = true;
        break;
      }
      ASSERT_EQ(6, tos0.getTimeouts());
      ASSERT_GE(6100, eventBase.getAvgLoopTime() - 1200);
      ASSERT_LE(6100, eventBase.getAvgLoopTime() + 1200);
      tos.reset(new IdleTimeTimeoutSeries(&eventBase, timeouts));
      break;

    default:
      FAIL() << "Unexpected latency callback";
      break;
    }
  });

  // Kick things off with an "immedite" timeout
  tos0.scheduleTimeout(1);

  eventBase.loop();

  if (hostOverloaded) {
    return;
  }

  ASSERT_EQ(1, latencyCallbacks);
  ASSERT_EQ(7, tos0.getTimeouts());
  ASSERT_GE(5900, eventBase.getAvgLoopTime() - 1200);
  ASSERT_LE(5900, eventBase.getAvgLoopTime() + 1200);
  ASSERT_TRUE(!!tos);
  ASSERT_EQ(21, tos->getTimeouts());
}
开发者ID:NextGenIntelligence,项目名称:folly,代码行数:66,代码来源:EventBaseTest.cpp


注:本文中的EventBase::setMaxLatency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。